Please help with NumberGuess exercise!


#1

When i try to run my code on NumberGuess, the console asks for my input (However, it does not show the text i put in for “raw_input”). When I enter a number, i get “bash: x: command not found.”

Please Help!

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 = randit(1, number_of_sides)
  second_roll = randit(1, number_of_sides)
  max_val = number_of_sides * 2
  roll_dice(6)
  print "The maximum possible value is:" + str(max_val)
  sleep(1)
  user_guess = get_user_guess()
  if user_guess > max_val:
    print "Guess is invalid."
    return
  else:
    print "Rolling..."
    sleep(2)
    print "The first value is: %d" % first_roll
    sleep (1)
    total_roll = first_roll + second_roll
    print total_roll
    print "Result..."
    sleep(1)
    if user_guess > total_roll:
      print "Congratulations!! You Won!!"
      return
    else:
      print "Aww!! Better Luck Next Time!!"
      return

#2

Well, first of all, there is a typo here:

should be randint.

also, it looks like you are trying to call your roll_dice function, inside of it’s definition, and I don’t believe this will work.


#3

duh what a dumb mistake. thank you so much. got it running!


#4

not a dumb mistake, everyone makes typo errors :wink:


#5

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