1
resposta

Resolução de Atividades - "09 Faça como eu fiz: dicionários"

lista_de_restaurantes = [{"nome": "Mc Donalds", "categoria": "Hamburguers", "estado": True},
                         {"nome": "Pizza Hut", "categoria": "Pizzas", "estado": False}, 
                         {"nome": "Casa do Pastel", "categoria": "Pastéis", "estado": False}]
                         
[...]

def cadastrar_restaurante():

    exibir_subtitulos ("Cadastro de Restaurantes")
    
    nome_do_restaurante = input ("Digite o nome do restaurante a ser cadastrado: ")
    categoria_restaurante = input ("Digite a categoria do restaurante: ")

    dados_do_restaurante = {"nome": nome_do_restaurante, "categoria": categoria_restaurante, "estado": False}

    lista_de_restaurantes.append (dados_do_restaurante)

    print (f"Restaurante {nome_do_restaurante} cadastrado com sucesso!")
    retornar_ao_menu()
    
def listar_restaurantes():

    exibir_subtitulos ("Lista de Restaurantes")

    print (f"{"Nome do Restaurante".ljust(28)} | {"Categoria".ljust(25)} | {"Estado".ljust(25)}\n")

    for restaurante_indice in lista_de_restaurantes:

        nome_restaurante = restaurante_indice["nome"]
        categoria_restaurante = restaurante_indice["categoria"]
        status_restaurante = "Ativo" if restaurante_indice["estado"] else "Inativo"

        print (f"*  {nome_restaurante.ljust(25)} | {categoria_restaurante.ljust(25)} | {status_restaurante.ljust(25)}")
    
    retornar_ao_menu()

def mudar_estado_restaurante():

    exibir_subtitulos ("Alterando restaurante do restaurante")

    nome_do_restaurante = input ("Digite o nome do restaurante: ")
    restaurante_encontrado = False

    for restaurante_indice in lista_de_restaurantes:

        if nome_do_restaurante == restaurante_indice["nome"]:

            restaurante_encontrado = True
            restaurante_indice["estado"] = not restaurante_indice["estado"]
            mensagem = f"O restaurante {nome_do_restaurante} foi ativado com sucesso!" if restaurante_indice["estado"] else f"O restaurante {nome_do_restaurante} foi desativado com sucesso!"

            print (mensagem)
    
    if not restaurante_encontrado:
        print ("Restaurante não foi encontrado!")

    retornar_ao_menu()
1 resposta

Ei! Tudo bem, Victor?

Sua resolução está bem estruturada e a lógica geral das funções está certa! Você usou dicionários, listas e controle de estado de forma adequada para o objetivo da atividade.

Muito bom trabalho na atividade! Continue assim e qualquer dúvida, compartilhe no fórum.

Alura Conte com o apoio da comunidade Alura na sua jornada. Abraços e bons estudos!