2021-11-26

If there are 2 inputs in python how to check which got new information last? [closed]

My program has 2 inputs and I want to check which is the last one to receive information.

It looks like this (sorry the variables and text arent in English):

jatekos1 = int(input("Hány gyufát veszel el, " + nev1 + "? "))
gyufa = gyufa - jatekos1
print(str(gyufa) + " gyufánk van.")

jatekos2 = int(input("Hány gyufát veszel el, " + nev2 + "? "))
gyufa = gyufa - jatekos2
print(str(gyufa) + " gyufánk van.")

How do I tell which one of these two I'm looking for?

edit: this is the working code, you will find the solution in there.

nev1 = input("Mi a neved, Játékos_1? ")
nev2 = input("Mi a neved, Játékos_2? ")

while True:

    gyufa = int(input("Hány gyufánk van? "))
    sz = 0
    while True:    
            
        jatekos1 = int(input("Hány gyufát veszel el, " + nev1 + "? "))
        gyufa = gyufa - jatekos1
        print(str(gyufa) + " gyufánk van.")
        sz += 1

        if gyufa == 0:
            if(sz % 2) == 0:
                print(nev1 + " nyert.")
            if (sz % 2) == 1:
                print(nev2 + " nyert.")
        if gyufa == 0:
            break
                
        jatekos2 = int(input("Hány gyufát veszel el, " + nev2 + "? "))
        gyufa = gyufa - jatekos2
        print(str(gyufa) + " gyufánk van.")
        sz += 1
        
        if gyufa == 0:
            if (sz % 2) == 0:
                print(nev1 + " nyert.")
            if (sz % 2) == 1:
                print(nev2 + " nyert.")  
        
        if gyufa == 0:
            break
        else:
            continue       
        
    again = input("Újra? i/n ")
    if "i" in again:
        continue
    else:
        break

So i just added a counter. if the number is odd it means the first input was used last. if its even that means the second input was used last.



from Recent Questions - Stack Overflow https://ift.tt/3CSbSut
https://ift.tt/eA8V8J

No comments:

Post a Comment