Exemple #1
0
    r = sample(range(10), input)
    print(f"Sorting {len(r)} values from the list » ", end='')
    for i in r:
        lst.append(i)
        print(i, end=' ', flush=True), sleep(0.5)


def sm():
    s = []
    for i in lst:
        if i % 2 == 0:
            s += [i]
    print(f"\n\nEven values are {s} and their sum is » {sum(s)}"), sleep(1)


raffle(5), sm(), end(), prof()


def sorteia(lista):
    print('Sorteando 5 valores da lista: ', end='')
    for cont in range(0, 5):
        n = randint(1, 10)
        lista.append(n)
        print(f'{n} ', end='', flush=True)
        sleep(0.3)
    print('PRONTO!')


def somaPar(lista):
    soma = 0
    for valor in lista:
Exemple #2
0
    if n == '':
        n = '<unknown>'
    if g.isnumeric():
        g = int(g)
    else:
        g = 0

    return f"Player '{n}' has scored {g} goal(s) in the league."


n = str(input("Type a name » ")).strip().title()
g = input("Number of goals  » ")

print(record(n, g))

end(), prof()


def ficha(jog='<desconhecido>', gol=0):
    print(f'O jogador {jog} fez {gol} gol(s) no campeonato.')


#Programa Principal
n = str(input("Nome do Jogador: "))
g = str(input("Número de Gols: "))
if g.isnumeric():
    g = int(g)
else:
    g = 0
if n.strip() == '':
    ficha(gol=g)
Exemple #3
0
title("Voting Functions")


def vote(i):
    v = date.today().year - i
    if v < 16:
        return f"\nWith {v} years » Cannot vote."
    elif v < 18 or v > 65:
        return f"\nWith {v} years » Optional vote."
    else:
        return f"\nWith {v} years » Mandatory vote."


i = int(input("Type date of birth » "))

print(vote(i)), end(), prof()


def voto(ano):
    atual = date.today().year
    idade = atual - ano
    if idade < 16:
        return f'Com {idade} anos: NÃO VOTA.'
    elif 16 <= idade < 18 or idade > 65:
        return f'Com {idade} anos: VOTO OPCIONAL.'
    else:
        return f'Com {idade} anos: VOTO OBRIGATÓRIO.'


nasc = int(input("Em que ano você nasceu? "))
Exemple #4
0
"""
   Exercício Python #113 - Funções aprofundadas em Python
   Crie um código em Python que teste se o site pudim está acessível pelo computador usado.
"""
from pattern import title, end
from lesson22 import validate

title("In-depth Python Functions")

i = validate.integer("Type a integer number » ")
r = validate.real("Type a real number » ")
print(f"The integer reported was {i} and the real was {r}")

end()
Exemple #5
0
    do Python, só que fazendo a validação para aceitar apenas um valor numérico.
    Ex: n = leiaInt('Digite um n: ')
"""
from pattern import title, end, prof
title("Validating data entry in Python"), prof()
def leiaInt(msg):
    ok = False
    valor = 0
    while True:
        n = str(input(msg))
        if n.isnumeric():
            valor = int(n)
            ok = True
        else:
            print("ERRO! Digite um número inteiro válido.")
        if ok:
            break

        while True:
            res = str(input("Do you wish to continue? [Y/N] » ")).strip().upper()[0]
            if res in "YN":
                break
            print("Option invalid. Try again.")
        
        if res == "N":
            break
    return valor
# Programa Principal
n = leiaInt("Digite um número: ")
print(f"Você abacou de digitar o número {n}"), end()