IndentationError: unexpected indent


I am going crazy trying different indents and everything I have tried causes another error. Here is my current dilemma, please help me understand what I'm missing.

File "", line 14                              
    print "Maxium Value is " + str(max_value)                 
IndentationError: unexpected indent          

"""Rolls a pair of dice and player guesses the number, then the computer tries to guess. Closest wins."""

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 "Maxium Value is " + str(max_value)
 		user_guess = get_user_guess()
  if user_guess > max_val:
			print "User guess is higher than Maxium Roll!"
  		print 'Rolling...'
  		print 'The first roll value is: %d' % first_roll
  		print 'The second roll value is: %d' % second_roll
  		total_roll = (first_roll + second_roll)
  		print 'The total roll value is: %d' % total_roll
  		print 'Result...'
  	if user_guess > total_roll:
      	print "You Won!! Great Job!"
  			print 'You have lost. Try again.'



I see that I was using both tabs and spaces. Is it better for me to use one over the other?

Also, on line 14 I was trying to print the string of max_value, it should be max_val.


Yes, use spaces or tabs.

Why this part of the code:

print "Maxium Value is " + str(max_value)
user_guess = get_user_guess()

has deeper indentation than the lines before?

The first if construction has a very small indentation, why?

I mean, this is not a black magic. Delete all indentations and start from there using only spaces or tabs.


I did just that and now it is working. I see where I went wrong. Thank you.


Great :slight_smile: You're welcome


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