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

问题描述 投票:0回答:1

为了学习和掌握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
python dice
1个回答
0
投票

嗯,如果您的变量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!")
© www.soinside.com 2019 - 2024. All rights reserved.