Search for elements in tuples within a list

Asked

Viewed 46 times

0

I made this code to search for an event, initially, I was unable to make the method print_events work, now it works, needs adjustments and improvements still and make work the formatting methods, if you can give a hint thank you!

    agenda = [
      ((2020, 1, 13), (11, 50), 'Renovar identidade'),
      ((2020, 1, 15), (16, 30), 'Fazer compras'),
      ((2020, 1, 25), (8, 45), 'Autenticar documentos'),
      ((2020, 2, 29), (14, 15), 'Prestar concurso'),
      ((2020, 3, 15), (17, 50), 'Buscar bolo pro aniversário da vovó'),
      ((2020, 3, 17), (13, 20), 'Consulta de revisão com dentista')]

def formatar_data(dia, mes, ano): #metodo para formatar a data
    dia_str = str(dia)
    meses = ['jan', 'fev', 'mar', 'abr', 'mai', 'jun',
        'jul', 'ago', 'set', 'out', 'nov', 'dez']
    mes_ext = meses[mes-1]
    ano_str = str(ano)
    return dia_str+"/"+mes_ext+'/'+ano_str
def formatar_hora(hr, min): #metodo para formatar a hora
    hr_str = str(hr)
    min_str = str(min)
    return hr_str+':'+min_str
def imprimir_eventos(agenda, de_data=()):
    for l in range(len(agenda)):
        if de_data in agenda[l]:
            print(agenda[l:])
data_inicial = ()
while True:
    continuar = str(input('Deseja pesquisar uma data (S/N)?')).upper()
    if continuar in 'S':
        print("Entre com a data inicial da pesquisa: ")
        dia = int(input('Digita o dia (dd): '))
        mes = int(input('Digita o mes (mm): '))
        ano = int(input('Digita o ano(aaaa): '))
        data_inicial = (ano, mes, dia)
        hr = int(input('Digite a hora: '))
        min = int(input('Digite o minuto: '))
        hr_inicial = (hr, min)
        imprimir_eventos(agenda, data_inicial)
    else:
        break
  • Use the module datetime: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.