-1
import math 
import time
from unittest import result 

print("welcome to the temerature converter ")

def again () :
    try_again = print("your temperature | C | F | K | ").upper()
    convert_temperature = input("The temperature you want to convert to | C | F | K | ").upper()
    
    if user_temperature == "c" :
        if convert_temperature == "F" :
            degree = float(input("enter the degree: "))
            result = (degree * 9/5) + 32
            print(f"{result}°F \nThe equation: ({degree} * 9/5) + 32 = {result}")
        elif convert_temperature == "K" :
            degree = float(input("enter the degree: "))
            result = degree + 273.15
            print(f"{result}°K \nThe equation: {degree} + 273.15 = {result}")
        elif  convert_temperature == "c" :
            print("this is the same type of temperature")
            time.sleep(1)
            again()

    elif user_temperature == "F" :
        if convert_temperature == "c" :

this is my code

rioV8
  • 24,506
  • 3
  • 32
  • 49

1 Answers1

0

It seems as if you never set user_temperature in this code. The easiest solution would be to have two inputs one for "convert_temperature" which is what unit of temperature the user wants to convert to and one input that is user_temperature which is the starting unit. Just add another input to fix your issue like. user_temperature = input("The starting temperature")

user_temperature = float(user_temperature) because you need to cast back to a number

Sam
  • 17
  • 3
  • 1
    There's also an issue with recursion, the code calls itself in the third `elif`. If this happens too many times it will probably crash with a maximum recursion error. Instead a while loop should be used. – David Waterworth Jan 21 '22 at 02:44