Omni-P
Omni-P

Reputation: 5

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

To learn and master the fundaments of python I made a dice program, but now that I finished it says that there is an syntax error and I don't understand what the error is. Can you help me out? I have searched for it but do really not understand were the mistake is.

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

Upvotes: 0

Views: 27

Answers (1)

MEDZ
MEDZ

Reputation: 2295

Well, Your variable y will always be yes if it was use for the first time. Also, I believe the error happens because you are using break and continue in else statement (while you actually can not).

I think what you are trying to do is like this:

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!")

Upvotes: 1

Related Questions