python - 如何在 Python 中退出循环?

标签 python syntax syntax-error

关闭。这个问题需要debugging details .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

5年前关闭。




Improve this question




我想让循环在 x + y =z 时停止,另外。

代码:

# -*- coding: utf-8 -*-
"""
Created on Mon Nov 16 18:39:40 2015

@author: gabri
"""

from random import randint
import os

x = randint(1,11)
y = randint(1,11)

print ("", x,"+", y,"=\n")
z = int(input("Resposta="))

if z == x + y:
    input ("\n\nCorreto\nPrima enter para continuar...")

else:
    for z in range(0, 10):
        os.system('CLS')
        input ("Incorreto.\n\n Tente de novo...")
        x = randint(1,11)
        y = randint(1,11)
        os.system('CLS')
        print ("", x,"+", y,"=\n")
        z = int(input("Resposta="))
        if z == x + y:
            input ("\n\nCorreto\nPrima enter para continuar...")
            exit

最佳答案

替换 exitbreak . Exit不是在 Python 中退出循环的方法。

break statement docs

关于python - 如何在 Python 中退出循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33742912/

相关文章:

python - Dash回调 'unexpected EOF while parsing'错误

python - 我如何用 PyObjects 声明一个 Boost.Python C++ 类

python - Python 中的 XML 到 CSV

python - 如何使用数据框列中的唯一值创建列表列表?

c++ - 可以显式指定构造函数的模板参数吗?

c++ - binary_search 总是返回真 C++

python - MySQL升级后django未处理的异常

Jquery 终端文本格式化语法,我做错了什么?

C:使用 void 指针的通用数据结构的更好语法?

php - mysql where子句中的未知列