from sys import exit
def gold_room():
print ("how much gold you need)")
amount = int(input("amount:"))
if 0 in amount or 1 in amount:
print(amount)
gold_room()
输出
how much gold you need)
amount:1
line 8, in gold_room
if 0 in amount or 1 in amount:
TypeError: argument of type 'int' is not iterable
Process finished with exit code 1
为什么会出现此错误?
答案 0 :(得分:0)
正如其他人提到的那样,您不清楚要做什么。如果您想打印amount
等于1或0,则可以使用此
from sys import exit
def gold_room():
print ("how much gold you need)")
amount = int(input("amount:"))
if 0 == amount or 1 == amount:
print(amount)
gold_room()
或者如果您要打印数字中的数字是1还是0(即123、220),则可以使用此
from sys import exit
def gold_room():
print ("how much gold you need)")
amount = input("amount:")
if '0' in amount or '1' in amount:
print(amount)
gold_room()