string to float python
# Use the function float() to turn a string into a float string = '123.456' number = float(string) number # Output: # 123.456
string to float python
# Use the function float() to turn a string into a float string = '123.456' number = float(string) number # Output: # 123.456
python could not convert string to float
#You have to simply convert a string to float. num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = num1 + num2 print(result) #In this case if user puts a number such as 10 + 10 it will be 20: 10 + 10 = 20 #if you don't convert it then it will add up the string like below num1 = input("Enter a number: ") num2 = input("Enter another number: ") result = num1 + num2 print(result) #The out put will be like so: "10" + "10" = 1010
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us