如何在while循环python中使用或运行?

时间:2015-04-25 23:07:13

标签: python while-loop

我的一些代码......

reenter = "T"
while reenter != "f" and reenter != "F":
    n1 = int(input("Please enter the first number in your equation : "))
    o = str(input("Please enter the operation (/,*,-,+)           : "))
    n2 = int(input("Please enter the second number in your equation: "))
    reenter = input(n1  + o + n2 is your Formula is this correct? T/F?")

我需要照顾资本化和非资本化的资金。问题是它不会退出循环,帮助??

提前感谢 - Zyrn

1 个答案:

答案 0 :(得分:0)

请勿使用input()进行用户输入,而不是raw_input()。 不同之处在于input()尝试评估用户输入,这不是您想要的。 还有其他一些字符串格式化等问题,请查看以下内容。

reenter = "T"
while reenter != "f" and reenter != "F":
    n1 = int(raw_input("Please enter the first number in your equation : "))
    o = raw_input("Please enter the operation (/,*,-,+) : ")
    n2 = int(input("Please enter the second number in your equation: "))
    reenter = raw_input("{}{}{} is your Formula is this correct? T/F?".format(n1, o, n2))

P.S。不确定你要做什么,但似乎你可能想要反转" T" /" F"有逻辑吗? :)