Untitled
unknown
python
a year ago
2.5 kB
5
Indexable
Never
from time import sleep def titulo(txt): print('-' * (len(txt) + 4)) print(f' {txt.center(len(txt))}') print('-' * (len(txt) + 4)) def leia_int(prompt): while True: try: n = int(input(prompt)) except (TypeError, ValueError): print('ERRO: digite um número inteiro válido') continue else: return n def menu(lst, title): titulo(title) for c, item in enumerate(lst): print(f'[ {c} ] {item}') while True: menu(['°F - °C', 'K - °C', '°F - K', 'Sair do programa'], 'CONVERSOR DE TEMPERATURA') opcao = leia_int('Sua opção: ') if opcao == 0: while True: menu(['°F -> °C','°F <- °C', 'voltar ao menu principal'], 'Escolha a opção desejada:') escolha = leia_int('Sua opção: ') if escolha == 0: f = leia_int('Temperatura em graus fahrenheit: ') print(f'{f}°F = {(f - 32) / 1.8}°C') if escolha == 1: c = leia_int('Temperatura em graus celcius: ') print(f'{c}°C = {(c * 1.8 + 32)}°F') if escolha == 2: break if opcao == 1: while True: menu(['K -> °C', 'K <- °C', 'voltar ao menu principal'], 'Escolha a opção desejada:') escolha = leia_int('Sua opção: ') if escolha == 0: k = leia_int('Temperatura em graus kelvin: ') print(f'{k} K = {(k - 273.15):.3f}°C') if escolha == 1: c = leia_int('Temperatura em graus celsius: ') print(f'{c}°C = {c + 273.15:.3f} K') if escolha == 2: break if opcao == 2: while True: menu(['°F -> K', '°F <- K', 'voltar ao menu principal'], 'Escolha a opção desejada:') escolha = leia_int('Sua opção: ') if escolha == 0: f = leia_int('Temperatura em graus fahrenheit: ') print(f'{f}°F = {(f + 459.67) * 5/9:.3f} K') if escolha == 1: k = leia_int('Temperatura em kelvin: ') print(f'{k} K = {1.8 * (k - 273) + 32:.3f}°F') if escolha == 2: break if opcao == 3: break print('-' * 35) print('ENCERRANDO...') sleep(1.5) print('PROGRAMA ENCERRADO! VOLTE SEMPRE!')