-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

どうすれば修正できますか?これは学校用であり、while ループを使用することを意図しているため、for ループの使用を提案しないでください。

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 に答える