NumberGuess Help


#1

I try getting this to run but when I put the command in to start running it, nothing will happen after. I’ve tried so many checking my code, what am I missing?

from random import randint
from time import sleep

def get_user_guess():
user_guess = int(raw_input("Guess a number: "))
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()

if user_guess > max_val:
print "No guessing higher than total value of dice roll!"
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 value is %d” % total_roll
print "Result…"
sleep(1)

if user_guess > total_roll:
print "You won!"
return
else:
print "Game lost!"
return
roll_dice(6)


#2

Hi @ cecilyal2,

Since your posted code is not formatted, we cannot see its indentation.

Make sure this statement is not indented in the code that you are executing …

roll_dice(6)

If it is indented, then it is part of the roll_dice function or a conditional block. and it will not execute. As a consequence, the roll_dice function will not get called.


#3

I did have the roll_dice(6) indented and I adjusted it so that worked. Thank you!


#4