I am learning python and I am getting error. Following is my code.
answer=5
print("Please guess a number between 1 and 10")
guess=int(input())
if guess<answer:
print("Please guess higher")
else:x>0
print("You got in first time")
Following is the error.
print("You got in first time")
IndentationError: unexpected indent
CodePudding user response:
else
doesn't take any conditions.
answer=5
print("Please guess a number between 1 and 10")
guess=int(input())
if guess<answer:
print("Please guess higher")
# else doesn't take any conditions.
else:
print("You got in first time")
CodePudding user response:
change the else condition to this-
elif x>0:
print("...")
CodePudding user response:
answer=5
print("Please guess a number between 1 and 10")
guess=int(input())
if guess<answer:
print("Please guess higher")
elif x>0 :
print("You got in first time")
Instead of else:x>0
the correct syntax for providing an else if condition is elif x>0 :
CodePudding user response:
The way else
is written needs to be updated, also there's no variable x
and hence your code might still fail. Here is the updated code:
answer=5
print("Please guess a number between 1 and 10")
guess=int(input())
if guess<answer:
print("Please guess higher")
elif guess>answer: # Updated elif here which was else earlier
print("Please guess lower")
else:
print ("You got it in first time")
CodePudding user response:
You have given an extra spcae in yhe last line.
Change this
if guess<answer:
print("Please guess higher")
else:x>0
print("You got in first time"
To
if guess<answer:
print("Please guess higher")
else:x>0
print("You got in first time"