Number guess


#1

Icant find my mistake, please help thanks

from random import randint
from time import sleep
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 "your maximum value is," + str(max_val)
    sleep(1)
    user_guess = get_user_guess()
    if user_guess > max_value:
      print "guess is invalid"
      return 
    else:
      print "Rolling..."
      sleep(2)
      print "%d" % first_roll
      sleep(1)
      print "%d" % second_roll
      total_roll = first_roll + second_roll
      print "Result..."
      sleep(1)
      if total_roll < user_guess:
        print "You have won!"
      else:
        print "You have lost"
roll_dice(6)


#2

user_guess = get_user_guess()

It seems you calling the get_user_guess function.but there is no the get_user_guess function in your code.
and here

if user_guess > max_value:

it should be max_val not max_value


#3

thanks for the reply it is now working but I still keep losing even when total_roll < user_guess. My guess was 11 and the the total_roll was 6. It still prints I have lost.


#4

can you please post the update version of your code?


#5

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