Indentation Problem


#1


I can't find out why terminal complains about indentation. I think there should not be any indentation problem, because there is no error message when I copy the code into my PyCharm. Can you help me check what's wrong with my code? Thanks!

File "NumberGuess.py", line 37
sleep(2)
^
IndentationError: unindent does not match any outer in
dentation level


from random import randint
from time import sleep


def get_user_guess():
    user_guess = int(raw_input("Guess a number: "))
    return 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_sides * 2
    print "The max values is " + str(max_val)
    sleep(1)
    user_guess = get_user_guess()
    if user_guess > max_val:
        print "Too large input."
        return
    else:
        print "Rolling..."
        sleep(2) #terminal complains about indentation here
        print "The first value is: %d" % first_roll
        sleep(1)
        print "The second value is: %d" % second_roll
        total_roll = first_roll + second_roll
        print "The result value is: %d" % total_roll
        sleep(1)
        if user_guess > total_roll:
            print "You won!"
            return
        else:
            print "You lost, try again."
            return


roll_dice(6)


#2

The posted code has valid indentation. Most likely the interpreter that was complaining about indentation was given some other code.


#3

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