How to get an integer input? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to get an integer input?

Im new at python, and have written a simple code that multiplies the input with 2. I did take an x variable wich is = input('enter a number') Then y = x * 2, then print (y). I have tried to cgange it in many ways, but i can never get an intwger input

12th Jan 2017, 9:51 AM
Balázs Rippl
Balázs Rippl - avatar
2 Answers
+ 1
This might help : x = int (input ("Enter a number ")) y = x * 2 print (y) Python doesn't evaluate and convert the data type, you have to explicitly convert to int
13th Feb 2017, 7:23 PM
Darko Churdy
- 1
Then the output is (when for example enter 4 in input): enter a number8. How to get simple an 8?
12th Jan 2017, 10:08 AM
Balázs Rippl
Balázs Rippl - avatar