while 循环中的语法错误或 Python 中我的骰子程序的输入

SyntaxError in while loop or input of my dice program in Python

为了学习和掌握python的基础,我做了一个骰子程序,但是现在我完成了它说有语法错误,我不明白错误是什么。你能帮我吗? 我已经搜索过了,但真的不明白错误是什么。

import random
x = random.randrange(10, 20, 1)
print(x)

y = input("roll again?")
while y = "yes":
    continue
    print(x)
else :
    print("thanks for using my app!")
    continue
    break

嗯,如果是第一次使用,您的变量 y 将始终为 yes。另外,我相信错误的发生是因为您在 else 语句中使用了 breakcontinue(实际上您不能)。

我认为你想做的是这样的:

import random
y = "yes" #set y to be yes by default

while y == "yes": # use == instead of =
    x = random.randrange(10, 20, 1)
    print(x)

    y = input("roll again?")
    #you do not need to use continue/break here
else :
    print("thanks for using my app!")