# Number Guess

#1

I made sure my indentation is identical with the code in hint section, but I am still getting errors. Where did I do wrong?

``````"""
I will build a program that rolls a pair of dice and asks the user to guess a number. Based on the user's guess, the program should determine a winner. If the user's guess is greater than the total value of the dice roll, they win! Otherwise, the computer wins.
"""
from random import randint
from time import sleep

def get_user_guess():
user_guess = int(raw_input('Enter 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 max possible number will be', str(max_val)
sleep(1)
user_guess = get_user_guess()
if user_guess > max_val:
print 'The number you entered is greater than the possible max number.'
return
else:
print 'Rolling...'
sleep(2)
print 'Your first roll is %d' % first_roll
sleep(1)
print 'Your second roll 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'Great job! You won the game!'
return
else:
print 'I am sorry, but you lost.'
return

roll_dice(6)``````

#2

all this code is incorrectly indented. Make sure it is on the same indentation level as your else: statement.

#3

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