NumberGuess game bug with indentation?


#1

Hi everyone, this is my first post in this forum :slight_smile:

The thing is… i have a problem with the NumberGuess game in Function Level of Learn python course.
This is my code, and i thing is right. Please check below:

"""Este programa fará as seguintes ações:
Rolar os dados; Adicionar o valor o resultado obtido da jogada; Pedir ao jogador para adivinhar e inserir um valor; Comparar os valores inseridos pelo utilizador, com os obtidos na jogada; Determinar o vencedor (Utilizador ou computador)"""

from random import randint
from time import sleep
def get_user_guess():
  guess = int(raw_input("Insira a sua aposta de resultado para a jogada dos dados: "))
  return guess

def roll_dice(number_of_sides): 
  first_roll = randint(1, 6) 
  second_roll = randint(1,6) 
  max_val = 6 * 2
  print "O valor máximo possivel é %d" % max_val
  guess = get_user_guess()
  if guess > max_val:
		print "O resultado apostado é demasiado elevado"
  else:
    print "Rolling..."
    sleep(2)
  	print 'Resultado da primeira rodada: %d ' % first_roll
    sleep(1)
    print 'Resultado da segunda rodada: %d ' % second_roll
    sleep(1)
    total_roll = first_roll + second_roll
    print 'O resultado total é: %d' % total_roll
    print "Result..." 
    sleep(1)
    if guess == total_roll:
      print "Ganhou!"
    else guess != total_roll:
      print "Perdeu!"
      
      
roll_dice(6)

-------------------------------------------------- code above------

When i put python NumberGuess.py + enter in console, it alert this:

$ python NumberGuess.py
File “NumberGuess.py”, line 21
print 'Resultado da primeira rodada: %d ’ % first_roll
^
IndentationError: unexpected indent

I don´t see any indentation problem with line 21 or in any other line in this code.

I can´t put corret indentation in this post, so i put this print of code: https://gyazo.com/135be84e5088232652057c2f53aadb2a

I appreciate any help.

Anyone can help me? :roll_eyes:


#2

this is a screenshot of your code:

image

you can see the indent problem? This is not your fault, the editor uses hard-tabs, and this sometimes messes stuff up. Re-indenting around line 21 should fix it.


#3

Tks, I am doing my first´s stapes in programming and i appreciate the clarification :+1:


#4

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