Number Guess Project indentation issue


#1

https://www.codecademy.com/courses/learn-python/projects/number-guess

Hi, I’m having trouble with indentation on the Number Guess Project. I have reviewed the video several times and been able to eliminate the other indentation errors but line 31 is still giving me an error. I think because the IF statement on this line is still nested in the previous else if should be indented to this level, but regardless of the level of indentation, or lack there of, I continue to receive indention errors. Any help correcting, and explaining what I’m doing wrong, would be greatly appreciated.

-Shawn


#2

why do line 30 (sleep(1)) and line 31 do not have the same indent level?


#3

They did originally, I believe that was one of the last things I changed while experimenting to determine what the source of the indentation error was.

The first time I wrote the code everything from line 21 to 30 was at the same indentation level.

I’ve tried writing this in Atom using only a fpur space tab, and I’m still getting stuck on line 31. Any ideas how I can fix this and what’s causing it?


#4

i would need to run the code to have a look, please copy paste the code to the forum. I can’t make this diagnoses based on screenshots


#5

Thanks for the help I’ve added the code below.

'''This program is a number guessing game that simulates rolling a pair of dice.'''

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 "No guessing higher than the maximum possible value %d" % max_val
    else:
        print "Rolling..."
    sleep(2)
    print "The 1st roll is: %d" % first_roll
    sleep(1)
    print "The 2nd roll is: %d" % second_roll
    sleep(1)
    total_roll = first_roll + second_roll
    print "The totatl value is: %d" % total_roll
    print "Result..."
    sleep(1)
    	if guess == total_roll
      	print "Correct! You guessed the right number"
      else:
        print "You did not guess correctly, try again"


roll_dice(6)


#6

Solved it. I started over and rewrote everything in Atom using the 4 space standard and that seemed to clear up the issues.

'''This program is a number guessing game that simulates rolling a pair of dice.'''

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 "No guessing higher than the maximum possible value %d" % max_val
    else:
        print "Rolling..."
        sleep(2)
        print "The 1st roll is: %d" % first_roll
        sleep(1)
        print "The 2nd roll is: %d" % second_roll
        sleep(1)
        total_roll = first_roll + second_roll
        print "The totatl value is: %d" % total_roll
        print "Result..."
        sleep(1)
    if get_user_guess == total_roll:
        print "Correct! You guessed the right number"
    else:
        print "You did not guess correctly, try again"

roll_dice(6)