嘿,谢谢你抽出时间帮助我,我会直截了当地说: 这只是一个小项目,我已经开始在我的GCSE之前练习我的Python技能了当前的问题我正在将一个数字添加到列表中,因为我已经完成了程序的每个部分。我设法解决所有当前的问题,但是,我无法解决这个问题所有/任何有关此问题的反馈/使程序更有效率将不胜感激。谢谢。
##code##
name = input("hello user what is your name?")
print("thank you for using our program:",name.title(),)
userchoice = input("which program would you like to use: add numbers,minus
numbers, alphabetical word order?")
#add numbers#
numList = []
addnewnumber = input ("would you like to add a new number?")
while addnewnumber == 'yes':
newnumber = input("what is your number?")
numList.append()
if addnewnumber == 'no':
numListsum = sum(numList)
print (numListsum)
##Console message##
RESTART: C:/Users/SWILS/AppData/Local/Programs/Python/Python36/python
coding/1.0.py
hello user what is your name?sean
thank you for using our program: Sean
which program would you like to use: add numbers,minus numbers, alphabetical
word order?add numbers
would you like to add a new number?yes
what is your number?6
Traceback (most recent call last):
File "C:/Users/SWILS/AppData/Local/Programs/Python/Python36/python
coding/1.0.py", line 11, in <module>
numList.append()
TypeError: append() takes exactly one argument (0 given)
答案 0 :(得分:1)
这对我有用->
append((item1 , item2))
答案 1 :(得分:0)
错误消息的含义正是它所说的:.append()
希望您传递一个参数,但实际上您没有传递任何参数。试试这个:
numList.append(newnumber)
答案 2 :(得分:0)
正确的语法是这样的:
numList = []
addnewnumber = input ("would you like to add a new number?")
while addnewnumber == 'yes':
newnumber = input("what is your number?")
numList.append(newnumber)
问题是您需要将值传递给append
的{{1}}方法,以便追加它。
答案 3 :(得分:0)
您的numList.append()
必须有一个参数
因此,请更改为此numList.append(newnumber)
。
答案 4 :(得分:0)
append
函数更新代码以执行您想要的操作:
name = input("hello user what is your name?")
print("thank you for using our program:",name.title(),)
userchoice = input("which program would you like to use: add numbers,minus
numbers, alphabetical word order?")
#add numbers#
numList = []
addnewnumber = input ("would you like to add a new number?")
while addnewnumber == 'yes':
newnumber = input("what is your number?")
numList.append(newnumber)
addnewnumber = input ("would you like to add a new number?")
numListsum = sum(numList)
print (numListsum)