|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大侠,
请帮忙看一下附件上的这段代码,为什么总是出现TypeError: steps() missing 1 required positional argument: 'number'
这问题出在哪里?
多谢!
David
#Write a function called "steps" that should return a string
#that, if printed, looks like this:
#
#111
# 222
# 333
#Note that the characters at the beginning of the second and
#third lines must be tabs, not spaces. There should be one
#tab on the second line and two on the third line.
#
#You may only declare ONE string in your function.
#
#Hint: Don't overthink this! We're literally just asking you
#to return one single string that just holds the above text.
#You don't have to build the string dynamically or anything.
#Write your function here!
def steps(number):
tabs =0
nums=1
for i in range(1,number+1):
string = tabs*"\t"+str(nums)*3+'\n'
tabs+=1
nums+=1
print(string)
return ''
#The line below will test your function.
print(steps(3))
print(steps(3))
111
222
333
[Executed at: Sun Nov 6 17:36:12 PST 2022]
We found a few things wrong with your code. The first one is shown below, and the rest can be found in full_results.txt in the dropdown in the top left:
We expected steps to return the str
"111
222
333". However, it instead encountered the following error:
TypeError: steps() missing 1 required positional argument: 'number' |
|