Can anyone help with my python program? (Basic Question)?

temp = input("Enter Temperature: ")

op = input("Enter CtoF or FtoC: ")

temp = float(temp)

def ctof(temp):

    f = (temp * 9/5) + 32

    print(f)

def ftoc(temp):

    c = temp - 32 * (5/9)

    print(c)

if "CtoF":

    ctof(temp)

elif "FtoC":

    ftoc(temp)

else:

    print("Error")

this is my code but it work properly. when i choose ftoc, it executes the ctof function. why? i also get a "This code is unreachable" error.

1 Answer

Relevance
  • Anonymous
    1 month ago
    Favorite Answer

    You never actually evaluated the "op" variable to see if is equal to "CtoF" or "FtoC"

    if (op == "CtoF"):

        ctof(temp)

Still have questions? Get your answers by asking now.