【发布时间】:2016-01-27 21:17:37
【问题描述】:
我想问一下我们如何在Python中使用变量来定义数组的大小(我的意思是列表)。我在下面写了一些代码,请你告诉我代码有什么问题? 谢谢..
elif(op=='+') :
size=int(input("Please enter how many numbers you want to add"))
for x in range(0,size):
print("Please enter the number",x+1)
inp=(input())
num[x]=inp #<<<-----the error comes up when trying to run this expression
for z in range(0,size):
num[z]=num[z]+num[z+1]
print("The result is " , num[size])
【问题讨论】:
-
你觉得哪里不对?缩进似乎是一个问题。
-
是
num已经声明为python dict 还是列表?? -
您是在尝试连接字符串 z 还是将 inp 中的数字作为整数相加?
-
我想将 inp 中的数字添加为整数,并通过询问用户来制作 num 列表
标签: python list calculator