0

I'm new and this is just a practice project to learn.

In the below code, the C and F selections work fine, but anything else stops the program. What I would like is for a way to make the script restart if anything other than C, c, F, f was entered.

Thanks in advance!

if unit == "c" or unit == "C":
    print("Okay, we are starting with Celsius")
    unitOpposite = "F"
    temp = int(input("Please enter temperature: "))
    print(temp, unit, " being converted to ", unitOpposite, "...")
    newtemp = int((temp * 9/5) + 32)
    print(temp, unit, " converted to ", unitOpposite, " is: ", newtemp, unitOpposite)
elif unit == "F" or unit == "f":
    print("Okay, we are starting with Farenheit")
    unitOpposite = "C"
    temp = int(input("Please enter temperature: "))
    print(temp, unit, " being converted to ", unitOpposite, "...")
    newtemp = int((temp - 32) * 5/9)
    print(temp, unit, " converted to ", unitOpposite, " is: ", newtemp, unitOpposite)
else:
    print("Entry incorrect. Please enter C or F")

0 Answers0