0
could someone show me a code on how too convert string into float please :) im stuck been trying to figure it out
4 Réponses
+ 2
>>> float(input("Enter a number: ")) + float(input("Enter another number: "))
Enter a number: 40
Enter another number: 2
42.0
I am confused about this one. I keep getting errors, any one can help me ? thanks!
+ 1
i guess it depends on what string you are trying to convert.
if you are trying to convert "3" to a float:
float("3") // returns 3.0
of you are trying to convert float("three"), i don't think you can do that
0
>>> float(input("Enter a number: ")) + float(input("Enter another number: "))
Enter a number: 40
Enter another number: 2
42.0
i am confused about this one. i keep getting errors and EOF
0
Ok, sorry you were left hanging so long. I am guessing the reason you didn't get an answer from anyone else sooner is because this thread is a day old at this point.
I think your getting the error because of the way the python interpreter on this site is running. when I run your code from a regular python interpreter it asks the user for input for each number and the result is 42.0
if you put your code in a print statement on this site, it does print the answer without the EOF error
print(float(input("Enter a number: ")) + float(input("Enter another number: ")))
but it lumps together the user input requests, and the output. Not exactly desirable but works. Was that the only issue you were having. If you were trying to store that for later use you need to assign the results to variables