0

Combining variables and if-statements

I thought it would be more interesting to combine a variable with the if-statement and here is what I have come up with: x = input("enter a number:\n") x = int(x) if x > 5: print(x," is greater than 5") print("Program ended") The thing that I don't understand is why the output includes the phrase "enter a number". Is that string part of x? But if it was then it shouldn't be possible to turn it into an integer. I'm confused and would appreciate if someone could explain it to me. Thanks!

17th Feb 2019, 3:33 PM
Timo Luege
3 Respuestas
+ 11
because, when you run the code on a ide. the string is shown as a prompt in the terminal. here's what you see enter a number: waits for a number to be given. enter a number:5 gets a number program ended
17th Feb 2019, 3:53 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 2
Thank you for the quick replies!
17th Feb 2019, 4:30 PM
Timo Luege
+ 1
Timo Luege you have a input as input ("enter a number") if you don't want to show the phrase "enter a number", simply have: x =int (input()) if x > 5: print(x," is greater than 5") print("Program ended")
17th Feb 2019, 3:58 PM
Sahil Danayak
Sahil Danayak - avatar