小编Eva*_*van的帖子

while循环正确嵌套

我正在寻求正确使用以下3个while循环的帮助:

while choice is None:  ...
while not isinstance (choice, int):  ...
while int(choice) not in range(0,1):  ...
Run Code Online (Sandbox Code Playgroud)

也许这样的东西:

while choice is None and not isinstance (choice, int) and int(choice) not in range(0,1):
    print("Invalid option!")
    choice = input("Choose key: ")
Run Code Online (Sandbox Code Playgroud)

我怎么能正确地嵌套这个?

choice = None
choice = input("Choose key: ")

while choice is None:
    choice = input("Choose key: ")

while not isinstance (choice, int):
    print("choice is an integer and I equal 0 or 1")
    print("Also if I am None or not …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

0
推荐指数
1
解决办法
75
查看次数

标签 统计

python ×1

python-3.x ×1