Hello, I was wondering if someone can help me out. When I run this it comes up asking Guess a number. I input a number and it will just keep on asking. Any help would be appreciated. Thank you. '''This is a computer dice game''' from random import randint from time import sleep def get_user_guess(): user_guess = int(raw_input('Guess a number: ')) return get_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_side * 2 print 'The maximum possible value is: ' + str(max_val) sleep(1) user_guess = get_user_guess() if user_guess > max_value: print 'This guess exceeds the max value' 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 total_roll print 'Result...' sleep(1) if user_guess > total_roll: print "you won!" else: print"You lost, try again." roll_dice(6)
If you use your
def get_user_guess(): user_guess = int(raw_input('Guess a number: ')) return get_user_guess()
you are recalling the
get_user_guess-function again and again and again....
You will want to change the function like
def get_user_guess(): user_guess = int(raw_input('Guess a number: ')) return user_guess
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.