0
How do you convert variable types?
In the following code the console on this app tells me I'm comparing a string to a int and thus it doesn't work. Is there a mistake in my code, or is it a problem with the app? x = input("enter a number") int(x) if x > 0: print("True ")
3 Answers
+ 1
Or you can write it as
X=int(input("enter a num"))
+ 1
if your input is numuerical string as "1"
you can use print(int("1"))
if your input is numuerical string as "a"
you can use print(ord("a"))
0
I set up new variable y. y becomes the x in integer format. see below
x = input("Enter a number: ")
y = int(x)
if y > 3:
print("True")