Skip to content
Advertisement

What am I doing wrong in this simple Python code?

— My goal is to make a code where user has to enter temperature, then user has to enter unit (C or F), then I wanna show conversion to F if users type C and vice versa. what wrong here tell me please I am super new to python and learning it all day, thanks.

JavaScript

Advertisement

Answer

You might want to pay more attention to strings.

  1. use string literals 'F' and 'C' (not bare F and C) in the if conditions.
  2. explicitly convert int to str by using str(), when you concatenate an int and str. Or better, use f-string.
JavaScript

By the way, I am afraid the formula is a little bit off. Another version, in which I corrected the formula and used f-string, is as follows:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement