为了学习和掌握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语句中使用了break
和continue
(实际上却不能)。
我认为您要尝试执行的操作是这样的:
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!")