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

Mat*_*ker 3 python input python-2.7

以下代码有问题:

start_over = 1

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

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

已解决,正在使用 input 而不是 raw_input

use*_*721 5

只需定义 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
Run Code Online (Sandbox Code Playgroud)