我一直在努力寻找一个小循环。我不知道为什么我的while
循环不起作用。如果我删除它工作的两个条件中的一个,但是当它们在一起时它不会......
temp = input("Choose between Fahreneit degrees 'f'' key or Celsius degrees 'c' key ")
while temp != "f" or temp != "c" :
temp = input("you must choose f or c")
if (temp == "f") :
print("you choosed Fahreneit")
degF = int(input("What is the temperature outside?"))
print("It seems that the temperature is around" , (0.56 * (degF - 32)) ,"Celsius from your Fahreneit sample")
elif (temp == "c") :
print("you choosed Celsius")
degC = int(input("What is the temperature outside?"))
while degC < -273 or degC > 5500 :
degC = int(input("Please enter a correct value"))
print("it seems that the temperature is around" , (1.8 * (degC) + 32) , "Fahreneit from your Celsius sample")
答案 0 :(得分:4)
temp != "f" or temp != "c"
与temp == "f" or temp == "c"
不同。有关否定布尔表达式的指导,请参阅De Morgan's laws。
尝试:
while temp != "f" and temp != "c":
或者只是:
while not (temp == "f" or temp == "c"):
或完全跳过布尔头痛:
while temp not in ("f", "c"):