0
why does this if-statement not work?
x = input("value of x") if x > 60: print ("uw bagage is te zwaar") elif x < 60: print ("u mag door lopen")
6 Answers
+ 6
Because the input function always returns a string, so your x variable is a string and you are trying to do math with it.
You must use int() to convert it.
wrap your input function inside an int() function. Like this:
x = int(input("value of x"))
And leave the rest of your code unchanged and test it. Hope it helps.
0
that doesn't work:-\
- 1
and you must modify x to be x=int(input("value of x")) and also you can use float if you want
- 1
here you go
x = input("value of x")
if int(x) > 60:
print ("uw bagage is te zwaar")
elif int(x) < 60:
print ("u mag door lopen")
did you forgot x==60? because your program wont do anything if user inputs exactly 60.
- 1
x = int(input("value of x")
that is enough to let it perfectly work
- 2
you must end if/elif statment by else
replace elif by else