我想通过在“istep”或“ito”中输入“0”来清除控制台,但只有当我在“ito”中输入“0”时才能清除控制台.有人能修复这个问题并解释这种行为的原因吗?谢谢!
import os
while True:
ifrom=int(input("From: "))
istep=int(input("Step: "))
ito=int(input("To: "))
if istep==0 or ito==0:
os.system('cls')发布于 2022-06-25 11:33:53
您需要使用几个if条件,因为ito只在用户输入istep的内容之后才获得一个值。
import os
while True:
ifrom=int(input("From: "))
istep=int(input("Step: "))
if istep==0:
os.system('cls')
ito=int(input("To: "))
if ito==0:
os.system('cls')发布于 2022-06-25 11:52:50
使用if-语句的值列表的更简单的解决方案
import os
while True:
ifrom=int(input("From: "))
istep=int(input("Step: "))
ito=int(input("To: "))
if 0 in [istep, ito]:
os.system('cls')https://stackoverflow.com/questions/72753508
复制相似问题