Dictionary exercise

Asked

Viewed 250 times

1

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

Exercise: Lavajet Management

Input: Each entry line starts with a letter ːE', ?R' or ?F', indicating the type of transaction to be conducted. 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 kind of service to be performed (great wax or wash). If the transaction is R' (withdraw), the rest of the row will contain only the first name of the customer having his car removed. Finally, the last line of the input will always be of the type F', indicating the closure car wash.

Output: For each transaction of the R' type, your program must print the last service that was performed on the car in question. In case there is no registered car under the requested name, print 'Unregistered User'.

Example:

Entree:

And Walter wax

R Heisenberg

R Walter

F

Exit:

Unregistered user

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

1 answer

1


You can before giving the split check which will be operation, just observe the first character of the input string (input[0])

See if that’s not 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
  • Exactly that! Thank you!

Browser other questions tagged

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