How do you convert variable types? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 ")

30th Jul 2016, 6:49 AM
Michael Hendricks
Michael Hendricks - avatar
3 Answers
+ 1
Or you can write it as X=int(input("enter a num"))
12th Aug 2016, 5:49 PM
Gulshan Kumar
Gulshan Kumar - avatar
+ 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"))
30th Aug 2016, 6:43 PM
beauty1234
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")
1st Aug 2016, 12:30 AM
Jenna
Jenna - avatar