Detective: Dúvidas

Asked

Viewed 74 times

1

Good afternoon dear! I have a big question in an activity of Python3! Follow the activity link: http://www.ic.unicamp.br/~mc102/Labs/roteiro-lab06.html

First, I’ll send you my code so you can understand how I thought and how I did it (without considering the solved cases, dead people, etc)

#-* coding utf-8-*-

N=int(input())
if N<0 or N>100:
    print("Valor inválido na entrada.")
else:
    caso={}
    deceased={}
    killer={}
    xeroque={}
    for n in range(N):
        assassino,vítima,detetive=input().split()
        caso[assassino]=["assassino"]
        caso[vítima]=["vítima"]
        caso[detetive]=["detetive"]
        deceased[vítima]=["vítima"]
        killer[assassino]=["assassino"]
        xeroque[detetive]=["detetive"]
        if assassino in detetive:
            caso[assassino]=caso[detetive]
for i in sorted(caso):
    print(60*"-")

    if i==assassino:        #ASSASSINO
        if i in deceased:
            print(str(i)+" (in memoriam):"+" assassino(a).")        
        elif i in xeroque:
            print(str(i)+" :"+" detetive.")
            break
        elif i in killer:
            print(str(i)+":"+" assassino(a).")  

    elif i==vítima:     #Vítima
        if i in killer:
            print(str(i)+" (in memoriam):"+" assassino(a).")
        elif i in xeroque:
            print(str(i)+" (in memoriam):"+" detetive.")
        else:
            print(str(i)+" (in memoriam):"+" vítima inocente.")

    elif i==detetive:   # Detetive
        if i in killer:     
            print(str(i)+":"+" detetive.")
        elif i in deceased:
            print(str(i)+" (in memoriam):"+" detetive.")
        elif i in xeroque:
            print(str(i)+":"+" detetive.")

print(sorted(caso.items()))
print(killer.items())
print(deceased.items())

So far I have done this. However, right in the third test (Maria Cicero Bianca and Maria Alan Bianca) goes wrong, since the output is like this:

2 maria Cicero Bianca

maria Alan Bianca

Alan (in memoriam): innocent victim.

Bianca: detective.


Maria: killer(the).

I cannot understand because the program does not read the Core, since I print the dictionary of case and victims and it appears as a victim in both!

  • One general suggestion I would give is to try to separate parts of the code that repeat into functions. This will make the code clearer and easier to debug.

No answers

Browser other questions tagged

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