-4

好吧,这个 python 程序打算从用户那里获取 2 个数字,一个是乘法表,它打算增加,一个是它应该停止的数字。这是到目前为止的程序:

count = 0

UI = 0

UserInput = 10

print ("Please type a number and press enter, this will be the multiplication table your sequence will go up in, then type another number and press enter, this will be the number the sequence will stop at.")

UI = int(input(""))

UserInput = int(input(""))

print = ("The program will now display all the numbers between your two numbers")

while all [count <= UserInput]:

      count = count*UI

      print (count)

但它一直在说:

Traceback (most recent call last):
  File "C:/Users/Shahriyar/Documents/DiffProg.py", line 11, in <module>
    while all [count <= UserInput]:
TypeError: 'builtin_function_or_method' object is not subscriptable

我如何解决它?并且请不要建议我使用 for 循环,因为这是用于学校的,我们打算使用 while 循环

4

2 回答 2

1

“它一直在说”:

Traceback (most recent call last):
  File "C:/Users/Shahriyar/Documents/DiffProg.py", line 11, in <module>
    while all [count <= UserInput]:
TypeError: 'builtin_function_or_method' object is not subscriptable

因为它复制的代码行在while all [count <= UserInput]:语法上无效。这不是python中的东西。

你可能想要while count <= UserInput:.

您的代码中还有其他错误。看看你是否可以通过测试找到它们。

于 2013-10-19T09:44:22.467 回答
0

我建议查看以下 python 文档:

http://docs.python.org/2/reference/compound_stmts.html#while

http://docs.python.org/2/library/functions.html

于 2013-10-19T09:56:45.137 回答