Home > Software design >  How to debug why a value in a loop is wrong in my Python program
How to debug why a value in a loop is wrong in my Python program

Time:02-20

Everything is correct in my code, but after running when the 2nd loop is executed 2 or times the value picked by system is something else and the value (added/subtracted) afterwards is something else..even in both case the variable used is same....

import random
player_1='Mr.BOT'
player_2=input('Enter your name : ')
print("                 RULES               \n(1)Each player will be given 9 marbles\n(2)One-by-One each player will hold some of their\n   marbles(it's upto them).\n(3)Other player will have to guess that if the number\n   of marbles that was picked by them is even or odd.\n(4)If the guess made by the other player is correct,\n   the player holding the marbles will have to give him\n   the marbles that he was holding,but if the other player\n   will make a wrong guess that player will now  have to\n   give the number of marbles that the player was holding\n   to that player himself..")
while True:
    while True:
        P_1=9
        P_2=9
        a=random.randint(1, P_1)
        if a%2==0:
            c='even'
        else:
            c='odd'
        d=input('Make your choice (even/odd) : ')
        if d==c:
            print('Your guess was correct....!!')
            P_1-=a
            P_2 =a
        else:
            print('You made a wrong guess....!!')
            P_1 =a
            P_2-=a
        print('Current status.......')
        print(player_1,'       ',player_2)
        print(' ',P_1,'         ',P_2)
        if P_1<=0 or P_2<=0:
            if P_1<=0:
                print(player_1,'LOSE.....           
  • Related