+ 1

Code not working

I was experimenting with a little begginers coding and wasn't sure what I did wrong: x = input("Enter number:") Enter number: 5 x*=4 print(x)

27th Apr 2019, 8:44 AM
Ola Michalewska
Ola Michalewska - avatar
6 Answers
+ 10
x is string, you should convert it to integer x = int(x)
27th Apr 2019, 8:46 AM
Salif Mehmed đŸ‡čđŸ‡·đŸ‡§đŸ‡Ź
Salif Mehmed  đŸ‡čđŸ‡·đŸ‡§đŸ‡Ź - avatar
+ 5
you can try this: x = int(input("Enter number:")) #Enter number: 5 x*=4 print(x) input() function does always create a string, regardless what you enter.
27th Apr 2019, 8:56 AM
Lothar
Lothar - avatar
+ 4
Ola Michalewska Option #2: x = int(input("Enter number:")) If you comment - "Enter number: 5" was written in the code without the "#" symbol, then by eliminating this error, the output will be: "5555". 👇 #Enter number: 5 x = input("Enter number:") x*=4 print(x) #Enter number: 5555
27th Apr 2019, 8:56 AM
Solo
Solo - avatar
+ 4
ola, i took the code to the Playground and saved it. It does work. To make sure that you get the steps done for properly run the code here a brief description. Click on the link below, it will load the code and display it. Press "Run" button. The input window from Playground pops up. Click in the input area inside the window, you will see the cursor blinking. Now input 5. After this press the "Submit" button. Playground will work a short time and then display the result which is 20. https://code.sololearn.com/cMZ0mPNqm717/?ref=app
27th Apr 2019, 7:03 PM
Lothar
Lothar - avatar
+ 1
I tried writing this code as you suggested, but it didn't work x = int(input("Enter number:")) #Enter number: 5 x*=4 print(x)
27th Apr 2019, 5:43 PM
Ola Michalewska
Ola Michalewska - avatar
+ 1
Thank you
27th Apr 2019, 9:57 PM
Ola Michalewska
Ola Michalewska - avatar