0
Why doesn't this conversion work?
print(float(input("5.0")) + float(input("5.0")))
11 Respostas
+ 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.
+ 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))
+ 1
Remember that when you type in multiple input's you need to leave a space between them.
+ 1
multiple
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.
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)
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. :(
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
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!
0
я по совету Дмитрия попробовал на части разбить этот код из примера. Все равно эта собака ругается, что не может преобразовать строку во флоат.
- 1
You can not input a string which contains text already. So it is not converted.