some syntax issues im facing with python
Hey so i have started with python recently and im facing a syntax error when im trying to activate this code with python 3.1 This code is from the Automate the Boring Stuff and it's exactly the same as the author used and mine is facing an Error, any idea ? btw the Error is with the elif condition
import random
print('Hello. What is your name?')
name = input()
print('Well, ' + name + ', I am thinking of a number between 1 to 20 ')
secretNumber = random.randint(1, 20)
for guessesTaken in range(1, 7):
print('Take a guess.')
guess = int(input())
if guess < secretNumber:
print('Your guess is too low.')
elif guess > secretNumber:
print ('Your guess is too high.')
else:
break
if guess == secretNumber:
print('Good job, ' + name + '! You guessed my number in ' + str(guessesTaken) + ' guesses')
else:
print(' Nope, that number i was thinking of was ' + str(secretNumber))
code with identation fixed which ran on my machine
import random
print('Hello. What is your name?')
name = input()
print('Well, ' + name + ', I am thinking of a number between 1 to 20 ')
secretNumber = random.randint(1, 20)
for guessesTaken in range(1, 7):
print('Take a guess.')
guess = int(input())
if guess < secretNumber:
print('Your guess is too low.')
elif guess > secretNumber:
print ('Your guess is too high.')
else:
break
if guess == secretNumber:
print('Good job, ' + name + '! You guessed my number in ' + str(guessesTaken) + ' guesses')
else:
print(' Nope, that number i was thinking of was ' + str(secretNumber))
Here is the correct indentation:
import random
print('Hello. What is your name?')
name = input()
print('Well, ' + name + ', I am thinking of a number between 1 to 20 ')
secretNumber = random.randint(1, 20)
for guessesTaken in range(1, 7):
print('Take a guess.')
guess = int(input())
if guess < secretNumber:
print('Your guess is too low.')
elif guess > secretNumber:
print ('Your guess is too high.')
else:
break
if guess == secretNumber:
print('Good job, ' + name + '! You guessed my number in ' + str(guessesTaken) + ' guesses')
else:
print(' Nope, that number i was thinking of was ' + str(secretNumber))