+ 1
Can anyone please show me how to do type-conversion from string to float using simple python coding?
5 Respostas
+ 5
a = float("45.678")
^ - the a variable is a float now
+ 3
To explicitly convert a string into a float, use the float() function.
"Python Type Conversion and Type Casting"
https://www.programiz.com/python-programming/type-conversion-and-casting
Example:
# initializing string
s = "10010"
# printing string converting to float
e = float(s)
print ("After converting to float : ", end="")
print (e)
+ 2
Alexander -
Code after correction:
print (float("enter a number:")+float("enter another number"))
The resulting error arises since you can't convert strings composed of characters other than numbers into an int or float value.
0
where is the mistake here= print (float(input("enter a number:")))+(float(input("enter another number"))))
0
try this:
print((float(input()))+(float(input())))
#count ur (), u’ll see the error