Why does this give me an error? | Sololearn: Learn to code for FREE!
+ 1

Why does this give me an error?

if 1 + int(input("enter a number: ")) == 2: if 1 + 2 == 3: print(True)

5th Apr 2017, 1:41 PM
Abbie Ruperto
Abbie Ruperto - avatar
3 Answers
+ 12
if (1 + int(input("enter a number: "))) == 2: print(True) else: print(False) Fixed.
5th Apr 2017, 2:00 PM
Hatsy Rei
Hatsy Rei - avatar
+ 7
Hi, Abbie! I think this is because of the second if block, just because of it does nothing. Because boolean for 1+2==3 is True, so writing if true: means nothing. The problem here is that Python is very indent sensitive language, so you should have either removed the second if statement or (if you for some reason need to keep it) removed the empty line (line 3) and add tabulation (indent) before print line
5th Apr 2017, 1:48 PM
Dinmukhamed Mailibay
Dinmukhamed Mailibay - avatar
+ 1
Or num = int(input("enter a number: ")) if 1 + num == 2: if 1 + 2 == 3: print(True) else: print (False) else: print(False) I don't know what is the logic u trying to build (r u tring nested if ) One more thing, Use variables it helps u to write readable code and avoid confusion.
5th Apr 2017, 3:35 PM
Eranga
Eranga - avatar