while True:
while True:
CF= input("Please select 1 (Celcius) or 2 (Fahrenheit)")
T= input("Please input temperature")
try:
CF= int(CF)
T=float(T)
#break
if CF==1 or CF==2:
break
else:
print("please input either 1 or 2")
except ValueError:
print("please input a number!")
print(f"Great! You chose option {CF} and temperature {T}. Now calculating...")
# (Your perfect loop stays exactly the same up here!)
if CF == 1:
result = (9 / 5) * T + 32
print(f"Celsius {T} degree = Fahrenheit {result} degree")
elif CF == 2:
result = (5 / 9) * (T - 32)
print(f"Fahrenheit {T} degree = Celsius {result} degree")
else:
print("Please input either 1 or 2 for the selection!")
print('-'*40)
# NEW EXIT CHALLENGE CODE:
quit_choice = input("Do you want to calculate another temperature? (y/n): ")
if quit_choice.lower() == 'n':
print("Thank you for using the temperature converter. Goodbye!")
break # This breaks the OUTER loop and closes the script!