Number Guess problem


Hey guys, so i started doing number guess and got pretty far in, however whenever i would enter python it would always show up as is the image i linked

I watched the youtube video to see what the guy did and i basically had the exact same thing as him yet i still can’t get it to work. Even when i go back to task 17 where it asks for you to give it a try i still get the same result.

here is my code:

This is a game to guess the number equal to 2 die's thrown in the simulation!

from random import randint
from time import sleep

def get_user_guess():
  guess = int(raw_input("guess a number!: "))
  return 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 %d" % max_val
    guess = get_user_guess()
    if guess > max_val:
      print "%d is tool large" % guess
      print "Rolling..."
      print "The 1st roll is %d" % first_roll
      print "The 2nd roll is %d" % second_roll
      total_roll = first_roll + second_roll
      print "The total value is %d" % total_roll
      print "Result..."
      if guess == total_roll:
        print "Congratulations! You have won!"
        print "Sorry mate, you have lost"

also link to the lesson


Hi @enrikolumaj

Indentation is essential in its defining the structure of a Python program. Check this line …

  def roll_dice(number_of_sides):

Is the roll_dice function global in scope, or is it part of the get_user_guess function?


you are a certified genius, i spent so long looking at indentation but i never thought of that one, just the ones below it.


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