Dictionary exercise

0

I can not solve this exercise. I need the letter that indicates the type of service (E, R or F) to be indicated in the same line as the other information, however, according to the inserted letter, the information requested is different, I do not know how to do it.

Exercise: Lava Management

Entry: Each entry line begins with a letter 'E', 'R' or 'F', indicating the type of transaction to be performed. If the transaction is of type 'E' (enter), the rest of the line will contain the first name of the client (without spaces), and what type of service to perform ('wax' or 'lavage'). If the transaction is 'R', the rest of the line will contain only the first name customer to have the car removed. Finally, the last line of the entry will always be type 'F', indicating the closing of the jet washer.

Output: For each transaction of type 'R', your program should print the last service which was performed on the car in question. If there is no car registered under the requested name, print 'User not registered'.

Example:

Entry:

And Walter Wax

R Heisenberg

R Walter

F

Output:

User not registered

wax

My code:

dicionario = {}

c=0

while c==0:

    letra = input()

    if letra=="E" :

        nome, serviço = input().split()

        dicionario.update({nome:serviço})

    elif letra== "R":

        nome1=input()

        if nome1 in dicionario.keys():

            print(dicionario[nome1])

        else:

            print("Usuário não cadastrado!")

    elif letra=="F":

        c=c+1
    
asked by anonymous 06.06.2017 / 17:56

1 answer

1

You can check the first character of the input string (input [0]) before you do the split.

See if it's more or less what you're trying to do:

dicionario = {}

c=0

while c==0:

    entrada = input("Digite o texto de entrada: (EX: E Walter cera)")

    if entrada[0] =="E" :

        opcao, nome, serviço = entrada.split()

        dicionario.update({nome:serviço})

    elif entrada[0] == "R":

        opcao, nome = entrada.split()

        if nome in dicionario.keys():
            print(dicionario[nome1])
        else:
            print("Usuário não cadastrado!")

    elif entrada[0] =="F":

        c=c+1
    
06.06.2017 / 19:04