Invalid syntax with else, check, please


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)
user_guess == get_user_guess()
if user_guess > max_value:
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"
print "You lost everything"


Line 30:
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.


@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:


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