TypeError: draw_row() takes exactly 5 arguments (6 given) on line 55
TypeError: draw_row() takes exactly 5 arguments (6 given) on line 55
我周五有作业要交,但我有一个问题,我的老师没有回复我,所以你能帮我吗?
我刚开始 python 乌龟在学校,这是我写的代码
from turtle import*
def square(square_color, length):
pd()
color(square_color)
begin_fill
for i in range(4):
fd(length)
lt(90)
end_fill()
pu()
fd(length)
speed(0)
n= int(input("Enter a number:"))
pu()
bk(n*25)
pu()
bk(n*25)
for cur_square in range(n):
if cur_square % 2 ==0:
square("black", 50)
if cur_square % 2 ==1:
square("red", 50)
if cur_square % 2 ==2:
square("gray", 50)
def draw_row(rows, length, square1_color, square2_color, cur_square):
for i in range(rows):
if(cur_square + i)% 2 ==0:
square(square1_color, length)
if (cur_square + i )%2 ==1:
square(square2_color, length)
def move_up(rows, length):
lt(90)
fd(length)
rt(90)
bk(rows*length)
length = int(input("The length of one square: "))
rows = int(input("The total amount of rows:"))
color1 = input("Color of the first square:")
color2 = input("Color of the second square:")
color3 = input("Color of the third square:")
speed(0)
pu()
setpos(-rows/2 * length, -rows/2 * length)
for cur_square in range(rows):
draw_row(rows, length, color1, color2, color3, cur_square)
move_up(rows,length)
它告诉我我有一个错误 - TypeError: draw_row() 在第 55 行
上恰好需要 5 个参数(给定 6 个)
我该怎么办?
我有错误的确切行
for cur_square in range(rows):
draw_row(rows, length, color1, color2, color3, cur_square)
move_up(rows,length)
错误信息很清楚,你定义了draw_row()
接受五个参数:
def draw_row(rows, length, square1_color, square2_color, cur_square):
然后到了调用它的时候,您通过了六个:
draw_row(rows, length, color1, color2, color3, cur_square)
根据定义,draw_row()
只处理两种颜色,square1_color
和 square2_color
:
def draw_row(rows, length, square1_color, square2_color, cur_square):
for i in range(rows):
if (cur_square + i) % 2 == 0:
square(square1_color, length)
else:
square(square2_color, length)
但是当你调用它时,你传入了三种不同的颜色,color1
、color2
和color3
。
我周五有作业要交,但我有一个问题,我的老师没有回复我,所以你能帮我吗?
我刚开始 python 乌龟在学校,这是我写的代码
from turtle import*
def square(square_color, length):
pd()
color(square_color)
begin_fill
for i in range(4):
fd(length)
lt(90)
end_fill()
pu()
fd(length)
speed(0)
n= int(input("Enter a number:"))
pu()
bk(n*25)
pu()
bk(n*25)
for cur_square in range(n):
if cur_square % 2 ==0:
square("black", 50)
if cur_square % 2 ==1:
square("red", 50)
if cur_square % 2 ==2:
square("gray", 50)
def draw_row(rows, length, square1_color, square2_color, cur_square):
for i in range(rows):
if(cur_square + i)% 2 ==0:
square(square1_color, length)
if (cur_square + i )%2 ==1:
square(square2_color, length)
def move_up(rows, length):
lt(90)
fd(length)
rt(90)
bk(rows*length)
length = int(input("The length of one square: "))
rows = int(input("The total amount of rows:"))
color1 = input("Color of the first square:")
color2 = input("Color of the second square:")
color3 = input("Color of the third square:")
speed(0)
pu()
setpos(-rows/2 * length, -rows/2 * length)
for cur_square in range(rows):
draw_row(rows, length, color1, color2, color3, cur_square)
move_up(rows,length)
它告诉我我有一个错误 - TypeError: draw_row() 在第 55 行
上恰好需要 5 个参数(给定 6 个)我该怎么办?
我有错误的确切行
for cur_square in range(rows):
draw_row(rows, length, color1, color2, color3, cur_square)
move_up(rows,length)
错误信息很清楚,你定义了draw_row()
接受五个参数:
def draw_row(rows, length, square1_color, square2_color, cur_square):
然后到了调用它的时候,您通过了六个:
draw_row(rows, length, color1, color2, color3, cur_square)
根据定义,draw_row()
只处理两种颜色,square1_color
和 square2_color
:
def draw_row(rows, length, square1_color, square2_color, cur_square):
for i in range(rows):
if (cur_square + i) % 2 == 0:
square(square1_color, length)
else:
square(square2_color, length)
但是当你调用它时,你传入了三种不同的颜色,color1
、color2
和color3
。