11
>>> 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
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Shohin
  • 548
  • 1
  • 3
  • 14
  • **Do not ever use `eval` for data that could possibly ever come from user input. It is a critical security risk that allows the user to run arbitrary code on your computer.** – Karl Knechtel Jul 27 '22 at 03:16

2 Answers2

21

floats can't be implicitly converted into strings. You need to do it explicitly.

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

But it's better to use format.

print("The value from Fahrenheit to Celsius is {0}".format(celsius))
Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
Jayanth Koushik
  • 9,476
  • 1
  • 44
  • 52
0

As the error says, you cannot covert float object to string implicitly. You have to do :

print("The value from Fahrenheit to Celsius is " + str(celsius))
jester
  • 3,491
  • 19
  • 30