-
Notifications
You must be signed in to change notification settings - Fork 0
/
011_fahrenheit_celsius.py
42 lines (32 loc) · 1.44 KB
/
011_fahrenheit_celsius.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def celsius_para_fahrenheit(celsius):
return celsius * 9/5 + 32
def fahrenheit_para_celsius(fahrenheit):
return (fahrenheit - 32) * 5/9
def menu():
while True:
print("\n===== Conversor de Temperaturas =====")
print("1. Converter Celsius para Fahrenheit.")
print("2. Converter Fahrenheit para Celsius.")
print("3. Encerrar/Sair do programa")
escolha = input("Digite o número da opção: ")
try:
escolha = float(escolha)
while True:
match escolha:
case 1:
celsius = float(input("Digite a temperatura em Celsius: "))
fahrenheit = celsius_para_fahrenheit(celsius)
print(f"{celsius:.2f}°C é igual a {fahrenheit:.2f}°F.")
break
case 2:
fahrenheit = float(input("Digite a temperatura em Fahrenheit: "))
celsius = fahrenheit_para_celsius(fahrenheit)
print(f"{fahrenheit:.2f}°F é igual a {celsius:.2f}°C.")
break
case 3:
print("Obrigado por usar o Conversor de Temperaturas. Até mais! =D")
exit()
except ValueError:
print("Digite um número válido. Use ponto como separador decimal.")
continue
menu()