0

I'm writing a code for a dice roll game and getting a weird syntax error. The syntax error I get for the script below is: invalid syntax: else: ^

import random num = random.randint(1, 7) def dice_roll(): gold = 0 input = ('Do you want to play again?' ) if num == 2: gold = (gold + 2) print (gold) print ('You Win!') print (input) if input != ('yes'): dice_roll() else: print ('Loser') dice_roll() 

Does someone know why this code would give me such an error?

2 Answers 2

2

Python is particular about indentation. Your else statement should have equal indentation as the above if-statement.

 if input != ('yes'): dice_roll() else: print ('Loser') 
Sign up to request clarification or add additional context in comments.

Comments

0

Else must be aligned with if, that is, shift two last lines to the left so that "else" was right under if.

1 Comment

Thanks I got it working, and understand the theory a little better now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.