0
Why doesnât this work?Iâm not sure why this doesnât work, can anyone explain why please
x = input(int()) if x > 5: print("x is greater than 5") if x < 5: print("x is greater thwn 5") else: print("x = 5")
3 RĂ©ponses
+ 4
There are 3 mistakes in your code. Here is the solution:
1. Mistake: x = input(int())
Correction: x =int(input())
2. Mistake: if x > 5: print("x is greater than 5")
Correction: if x > 5: print(str(x)+ " is greater than 5")
Or if x > 5: print(f "{x} is greater then 5")
3.Mistake: if x < 5: print("x is greater than 5")
Correction: elif x > 5: print(str(x)+ " is less than 5")
Or elif x > 5: print(f "{x} is less than 5")
0
Your input line is wrong. The correct syntax for taking in an integer input is as follows
x=int(input())
0
x = int(input())
if x > 5:
print(f"{x} is greater than 5")
elif x < 5:
print(f"{x} is less than 5")
else:
print(f"{x} = 5")
#Or
x = int(input())
if x > 5:
print(str(x)+" is greater than 5")
elif x < 5:
print(str(x)+" is less than 5")
else:
print(str(x)+" = 5")