python - 如果输入等于字符串,做一些事情...... python 2.7

标签 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

最佳答案

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

关于python - 如果输入等于字符串,做一些事情...... python 2.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19054661/

相关文章:

python - 在Python中循环遍历图像中每个像素的更快方法?

Python 迭代工作表并删除列

python - 如何使用矢量化方法来计算多维数组之间的成对曼哈顿/L1 距离?

python - 检查 OrientDB 中的类创建

forms - 更新一个 formControl,它是 Angular2 中 formArray 中的文件输入

python - 导入错误 : cannot import name 'TimedJSONWebSignatureSerializer' from 'itsdangerous'

Python 2.7 变量类型保持为 int32 而不是转换为 long

python - Tkinter GUI 中的多线程,不同类中的线程

html - 构建特定复杂表单的最佳实践/模式

Java:自动检测输入文件路径