Problem with step 25 (line 34 in code) getting invalid Syntax


#1

<I am receiving an invalid syntax error for line 34 of my code, for the else: function

what am I doing wrong?



#this program is meant to play a game where the user guesses a number greater than the total value of the dice roll, if they do, they win

from random import randint
from time import sleep

def get_user_guess():
  	user_guess = int(raw_input("Guess a number buddy"))
  	return user_guess
roll_dice()
def roll_dice(number_of_sides):
  	first_roll = randint(1, number_of_sides)
def roll_dice(number_of_sides):
  	second_roll = randint(1, number_of_sides)
max_val = number_of_sides * 2
print "The maximum possible value is drumrollllll please" + str(max_val)
sleep(1)
user_guess = get_user_guess()
if user_guess > max_val:
	print "Your guess is not valid"
	return
else:
  print "Rolling"
sleep(2)
print "The first value is... %d !" % first_roll
sleep (1)
print "The second value is... %d !" % second_roll
total_roll = first_roll + second_roll
print total_roll
print "Result..."
sleep(1)
if user_guess > total_roll:
	print "You are much luckier than I friend, well played"
return
else:
  print "You lost, try again"
  return
roll_dice(6)


#2

i think you need to walk through the indent of your entire code, for example here:

if user_guess > total_roll:
	print "You are much luckier than I friend, well played"
return
else:

else has to be after if, but because return has no indent, else is after return

You either need to: indent return properly and make sure its also in a function (its currently not) or remove return


#3

I have since corrected my indentations, but am now getting an indentation erro for line 13 with max_val


#4

why does the indent of this two lines (12 and 13):

  second_roll = randint(1, number_of_sides)
        	max_val = number_of_sides * 2

it should match, i don’t see why max_val would be additional indent compared to the line before


#5

I have since fixed it :slight_smile:

Thanks for your assistance!


#6