Created
August 27, 2020 01:47
-
-
Save go4Mor4/831c7d415539c9e91e6f96ae5a465709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ex 1: | |
from math import ceil | |
__table = [['5-9', 125], ['9.1-16', 250], ['16.1-24', 375], ['24.1-30', 500]] | |
def get_idade_peso(): | |
try: | |
idade = int(input('Digite a sua idade: ')) | |
peso = float(input('Digite o seu peso (em kg): ')) | |
except: return False | |
else: | |
if idade < 1 or peso <= 0: return False | |
else: return (idade, peso) | |
def calculate_mg(idade, peso): | |
if idade >= 12 and peso > 5: | |
if peso >= 60: return 1000 | |
else: return 875 | |
elif idade < 12 and peso > 5: | |
for table_data in __table: | |
if peso > float(table_data[0].split('-')[0]) and peso <= float(table_data[0].split('-')[1]): return table_data[1] | |
else: return 750 | |
else: return False | |
def app(): | |
result = get_idade_peso() | |
if not result: print('Você cometeu um erro.') | |
else: | |
idade, peso = result | |
mg = calculate_mg(idade, peso) | |
if not mg: print('Você não pode tomar este medicamento.') | |
else: print(f'Você deve tomar {int(ceil((mg / 500) * 20))} gotas de Dipirona!') | |
if __name__ == '__main__': app() | |
''' TESTES UNITÁRIOS | |
Teste 1: | |
idade = 10 | |
peso = 30 | |
output = 30 gotas | |
Teste 2: | |
idade = 16 | |
peso = 60 | |
output = 40 gotas | |
Teste 3: | |
idade = 1 | |
peso = 3 | |
output = Você não pode tomar este medicamento | |
''' | |
# Ex 2: | |
def get_cor_num(): | |
try: | |
cor = input('Digite "Verde" ou "Vermelho: ').upper() | |
num = int(input('Digite um número: ')) | |
except: return False | |
else: | |
if cor not in ['VERDE', 'VERMELHO'] or num not in range(1, 11): return False | |
else: return (cor, num) | |
def app(): | |
result = get_cor_num() | |
if not result: print('Você cometeu um erro.') | |
else: | |
cor, num = result | |
if cor == 'VERDE': print(f'\nVerde {", ".join(map(str, list(range(1, num+1))))}') | |
else: print(f'\nVermelho {", ".join(map(str, list(range(num+1))[::-1]))}') | |
if __name__ == '__main__': app() | |
''' TESTES UNITÁRIOS | |
Teste 1: | |
cor = VERDE | |
número = 4 | |
output = Verde 1, 2, 3, 4 | |
Teste 2: | |
cor = VERMELHO | |
número = 6 | |
output = Vermelho 6, 5, 4, 3, 2, 1, 0 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment