我试着用一段简单的代码,知道某人的名字和年龄,让他/她知道他们什么时候满21岁。。。不考虑消极因素,只是随机的。
我一直收到这个'int' object is not subscriptable
错误。
name1 = raw_input("What's your name? ")
age1 = raw_input ("how old are you? ")
x = 0
int([x[age1]])
twentyone = 21 - x
print "Hi, " + name1+ " you will be 21 in: " + twentyone + " years."
当你写
x = 0
时,x
是一个int…所以你不能做x[age1]
,因为x
是int
问题出在队伍里
你想要的是
您还需要将int转换为输出的字符串。。。
整个剧本看起来像
当您键入
x = 0
时,这将创建一个新的int
变量(名称)并为其赋值零。当您键入试图访问第
age1
条目的x[age1]
时,就好像x
是一个数组一样。相关问题 更多 >
编程相关推荐