如果输入等于字符串,请执行某些操作... python 2.7

时间:2013-09-27 15:32:49

标签: python python-2.7 input

遇到以下代码问题:

start_over = 1

question = input("Do you wish to try again? y/n: ")
if question == "y":
    start_over -= 1
else:
    raise SystemExit

如果他们输入y,则直接进入else条件。

解决了,是使用输入而不是raw_input

1 个答案:

答案 0 :(得分:3)

只需定义start_over ......就可以了

question = raw_input("Do you wish to try again? y/n: ")
start_over = 10
if question == "y":
    start_over -= 1
    print start_over
else:
    raise SystemExit