这就是我所尝试的,基本上我想做的是,如果用户输入的不是1,2,3,4,6,那么它将返回a=int(input.....))。但对我来说,它一直输出为None。
def hi():
while True:
try:
a=int(input("enter the denominator of Pi radiann"
"(choose from 1,2,3,4,6)n"
"Enter here:"))
if a <=0 or a>=7 and a!=5:
print("Enter the given digits")
else:
return a
except Exception:
print("enter a valid type")
ant=hi()
print(ant)
您在这里应用了错误的条件:
if a <=0 or a>=7 and a!=5:
你检查a!=5
作为一个错误的输入,当它应该是a==5
。也用or
代替and
。改为:
if a <=0 or a>=7 or a==5: