IndentationError: unexpected indent


#1


It says "IndentationError: unexpected indent"


 '''This is a computer dice game'''

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 maximum possivle value is:" + str(max_val)
  sleep(1)
  
  user_guess = get_user_guess
  
  if user_guess > max_val:
    print "No guessing higher than the maximum value!"
		return  
  else:
    print "Rolling..."
    sleep(2)
    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 total_roll
    
  	print "Result..." 
 		sleep(1)
    
  if user_guess > total_roll:
  	print "There you go!"
  else :
  	print "Try again"
    return
    
roll_dice(6)

Thank you!


#2

print and return should have the same indent level:

print "No guessing higher than the maximum value!"
		return

they clearly have not, same here:

    print "The second value is: %d" % (second_roll)

		total_roll = first_roll + second_roll
		print total_roll
    
  	print "Result..." 
 		sleep(1)

indent in python is crucial, given there are no brackets used like most other langauges


#3

Thank you for your advice!
I've cleared all indents but it is still showing same message.
Could you help me?

 '''This is a computer dice game'''

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 maximum possivle value is:" + str(max_val)
  sleep(1)
  
  user_guess = get_user_guess
  
if user_guess > max_val:
  print "No guessing higher than the maximum value!"
  return  
else:
  print "Rolling..."
    sleep(2)
  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 total_roll
    
  print "Result..." 
 		sleep(1)
    
if user_guess > total_roll:
  print "There you go!"
else :
  print "Try again"
  return
    
roll_dice(6)

#4

all this lines:

  print "Rolling..."
    sleep(2)
  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 total_roll
    
  print "Result..." 
 		sleep(1)

should have the same indent, they clearly have not


#5

It looked fine from my board but it kept showing that message. After I pasted it on question board, I could see what is wrong with indentation. so I went back and forth, copy and paste to correct indentation.

Now it shows different messages saying "command not found".
I thought roll_dice(6) as command. Did I miss colon or something,,,?

'''This is a computer dice game'''

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 maximum possivle value is:" + str(max_val)
 sleep(1)
  
 user_guess = get_user_guess
  
if user_guess > max_val:
 print "No guessing higher than the maximum value!"
 return  
else:
 print "Rolling..."
 sleep(2)
 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 "Result..." 
 sleep(1)

if user_guess > total_roll:
 print "There you go!"
 else :
 print "Try again"
 return
	
roll_dice(6)

#6

please read how to use markup:

So i can run the proper version of your code


#7

I think I have used triple backticks to show my code... does it appear as black line?
Following codecademy pro team's advice, I'll try to review python course from beginning again.
Thank you for your help!


#8

i can help you, but if you have indention problems, you need to get the markup right, othwerise it is impossible for me to help you


#9

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