the code in the question gives error when run | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

the code in the question gives error when run

float("210"*int(input("enter the number:")))

8th Sep 2016, 9:17 AM
bhavya
6 Answers
+ 2
input() returns a string. If you feed int() a string that has not the shape of an int (like "1.2"), it will cause an error. Convert the string to a float first, then to an int. print(float(210*int(float(input("enter the number:")))))
8th Sep 2016, 9:25 AM
Zen
Zen - avatar
0
it still gives an error "can't convert string into float"
8th Sep 2016, 9:29 AM
bhavya
0
Maybe you are typing 1,2 (comma) instead of 1.2 (dot)? Maybe you used quotes/double quotes in your input? Please give an example of input otherwise.
8th Sep 2016, 9:33 AM
Zen
Zen - avatar
0
I tried the code in the Playground and no error occurs. When I added a print function (@Zen) and entered 2, I get the expected result. The code seems to be okay.
8th Sep 2016, 12:03 PM
Amarie
0
the error ' can't convert string into float' occurs, when you try to convert a combination of letters into a float and that doesn't work. But when you enter a number it should work. In any case, your program seems to try to convert something that can't work.
8th Sep 2016, 12:14 PM
Amarie
0
It only errors if you put in one number. If you put in two, separated by a new line, it works fine
26th Oct 2016, 2:14 AM
Rupert Watson
Rupert Watson - avatar