NumberGuess project. Return outside function?


#1



I get a syntax error on line 21, 'return' outside function


I'm not sure what's causing this, any help would be muchly appreciated.


from random import randint
from time import sleep

def get_user_guess():
  user_guess = int(raw_input("Make your guess."))
  return 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 "The maximum possible value is" + str(max_val)
  sleep(1)
  user_guess = get_user_guess()
  
roll_dice(6)

if user_guess > max_val:
  print"That guess is to high!"
  return 
else:
  print"Rolling..."
  sleep(2)
  print"The first value is: %d" % first_roll
  sleep(1)
  print"The second value is: %d" % second_roll
  sleep(1)
  total_roll == first_roll + second_roll
  print"The total roll is: %d" % total_roll
  print"Result..."
  sleep(1)
  if  user_guess > total_roll:
    print"Congratulations, you have won!"
    return
  else:
    print"You lost, better luck next time!"
    return


#2

It looks like everything below,

should be inside the function code body. Be sure the indentation is consistent.


#3

Thank you! I've just been going over it again and again, just clicked. Thanks again :slight_smile:


#4

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