0

Why doesn't this conversion work?

print(float(input("5.0")) + float(input("5.0")))

23rd Aug 2016, 9:48 PM
Cris
11 Réponses
+ 3
do you actually input something when the script awaits for it? if you want to convert strings and add 5.0 to 5.0, just write: print(float("5.0")+float("5.0")) input() function writes it's argument on the screen and awaits for user to type something, and returns that. it does not return what you write in brackets.
24th Aug 2016, 7:40 AM
Demeth
Demeth - avatar
+ 2
in input waits for input.but you give in 5.0 in input function .it gives an error.just write print(float(5.0)+float(5.0))
25th Aug 2016, 5:07 AM
harish tati
+ 1
Remember that when you type in multiple input's you need to leave a space between them.
24th Aug 2016, 8:01 PM
Darth Vador
Darth Vador - avatar
+ 1
multiple
4th Jan 2017, 10:05 PM
Muhammad Ali
Muhammad Ali - avatar
0
I'm suposed to be inputing two strings that will be comverted to floats and the added together arithmetically. But it doesn't convert the strings to floats no matter what I input. It just gives me an error.
24th Aug 2016, 10:03 AM
Cris
0
try to break apart all those operations, maybe you'll see where it crashes. when it works in parts, you can step by step combine operations to one string if you want. start from this: inp1 = input('first:') inp1 = float(inp1) inp2 = input('second:') inp2 = float(inp2) print(inp1 + inp2)
24th Aug 2016, 10:18 AM
Demeth
Demeth - avatar
0
This all make sense, but I am going through this course and I haven't made it to the variables section yet, so I don't think I should need to use them to solve this exercise. The exercise appears exactly as what I wrote in the question above, but instead of the "5.0"s, it has the "Please enter input: " line and is asks me to enter something to make it work. I entered floats, integers, words, and nothing makes it work. :(
24th Aug 2016, 8:06 PM
Cris
0
just tried your code in this app's playground everything works fine, one thing that could possibly lead to errors - did you input your floats/ints in line, separating with spaces, or one-at-line, making a new line for each number? because only second option is correct for this app, it does not act like a real interpreter and wants all inputs before running a script
24th Aug 2016, 8:20 PM
Demeth
Demeth - avatar
0
I put it how it looks above, but if you say it worked in the ayground, that's good enough for me. I just didn't really want to move on without knowing why was it not working. Thanks a lot!
24th Aug 2016, 8:30 PM
Cris
0
я по совету Дмитрия попробовал на части разбить этот код из примера. Все равно эта собака ругается, что не может преобразовать строку во флоат.
18th Sep 2016, 11:25 PM
PhisX's Channel
PhisX's Channel - avatar
- 1
You can not input a string which contains text already. So it is not converted.
4th Jan 2017, 4:46 PM
Gaurang Mudgal
Gaurang Mudgal - avatar