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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19054661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:39:09  来源:igfitidea点击:

if input equals string, do something... python 2.7

pythonpython-2.7input

提问by Matt Walker

Having trouble with the following code:

以下代码有问题:

start_over = 1

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

If they enter y, it goes straight to the elsecondition.

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

Solved, was using input instead of raw_input

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

采纳答案by user1525721

Just define start_over...it will work

只需定义 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