Invalid syntax with else, check, please


#1

Roll dice game!

from random import randint
from time import sleep

def get_user_guess():
user_guess = raw_input("Your number?")
return int(user_guess)

def roll_dice(number_of_sides):
first_roll = randint(1, number_of_sides)
second_roll = randint(1, number_of_sides)
max_val = number_of_sides * 2
print str(max_val)
sleep(1)
user_guess == get_user_guess()
if user_guess > max_value:
print "NONONONONONONO"
return
else:
print "Rolling, mofu..."
sleep (2)
print "%d and %d" % first_roll, second_roll
total_roll = first_roll + second_roll
print "Result... "
sleep (1)
if user_guess > total_roll:
print "Graz"
return
else:
print "You lost everything"
return

roll_dice(6)

Line 30:
else:
SyntaxError: Invalid Syntax

So, guys, I need your help. I know, there must be simple way to sovle it, but i cant find it, it would be great, if you'll help me!
Thank you.
`


#2

@sirshurf: Whenever you post your code, make sure to indent it and use the [code] command so it will make it easier to help you out.
What does seem to be causing this error is the fact you have a whole bunch of return statements outside your conditional's scopes.

Make sure all your return statements are inside each scope.
Why that happened? No idea, too tired to think about it, sorry.
Also, you should check out a few things:

user_guess == get_user_guess()

Was that meant to be user_guess saving the value of get_user_guess() or it was just a comparison?

max_val = number_of_sides * 2
print str(max_val)
if user_guess > max_value:

max_value hasn't been declared but max_val has, check that!

print "%d and %d" % first_roll, second_roll

This will cause an issue because without using the parenthesis in your string formatting, Python will only see first_roll and consider all the rest as arguments for the print function.

But good job, quite a fun game! :sunny:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.