Код: Выделить всё
def convert_temperature(temperature, target_unit):
if target_unit != "F" and target_unit != "C":
return 1
else:
if target_unit == "F":
result = temperature * (9 / 5) +32
print(f"Converted temperature: {result:.2f} F")
elif target_unit == "C":
result = (temperature - 32) * (5 / 9)
print(f"Converted temperature: {result:.2f} C")
else:
return 1
temperature = float(input("Enter temperature value: "))
target_unit = str(input("Enter target unit (C/F): "))
convert_temperature(temperature, target_unit)
Подробнее здесь: https://stackoverflow.com/questions/793 ... a-recursiv
Мобильная версия