>> def main(): fahrenheit = eval(input("Enter the value for F: ")) celsius = fahrenheit - 32 * 5/9 p...">

"Cannot convert float to str implicitly"

>>> def main():
        fahrenheit = eval(input("Enter the value for F: "))
        celsius = fahrenheit - 32 * 5/9
        print("The value from Fahrenheit to Celsius is " + celsius)
>>> main()
Enter the value for F: 32
Traceback (most recent call last):  
  File "<pyshell#73>", line 1, in <module>
    main()
  File "<pyshell#72>", line 4, in main
    print("The value from Fahrenheit to Celsius is " + celsius)
TypeError: Can't convert 'float' object to str implicitly"
+4
source share
2 answers

floatscannot be implicitly converted to strings. You need to do this explicitly.

print("The value from Fahrenheit to Celsius is " + str(celsius))

But better to use format.

print("The value from Fahrenheit to Celsius is {0}".format(celsius))
+11
source

As the error says, you cannot hide a float up to a string implicitly. You must do:

print("The value from Fahrenheit to Celsius is " + str(celsius))
0
source

Source: https://habr.com/ru/post/1531708/


All Articles