Dice rolling game outputs incorrect information

Question:

My code is basically a dice rolling game, but at the end, the code is meant to state how far ahead player 1 beat player 2, but the code outputs random integers that I believe don’t correlate to anything


    import random
    Round = int(input("Developer use only, set to 5 otherwise "))
    p1_extra = 0
    p1_total = 0
    p1_turns = 5
    p2_extra = 0
    p2_total = 0
    p2_turns = 5
    for i in range (Round):
        p1_go = input("Please type 'ROll' to roll the dice, Player One ")
        while p1_go != ("ROLL"):
            p1_go = input("Please type 'Roll' to roll the dice. (caps sensitive)")
        p1_roll_1 = random.randint(1,6)
        p1_roll_2 = random.randint(1,6)
        p1_add = (p1_roll_1) + (p1_roll_2)
        p1_total = p1_add + p1_total
        print ("P1: On your first roll you got " , p1_roll_1 , ". On your second roll you got " , p1_roll_2 , ". In total you have " , p1_total)
       
        
    if p1_total % 2 == 0:
        print ("Player One Got An Extra 10 Points For Getting An Even Number! ")
        p1_total = (p1_total) + 10
        print ("Player Ones Total Is Now " , p1_total)
    else:
        print ("Player One Lost 5 Points For Getting An Odd Number! ")
        p1_total = (p1_total) - 5
        print ("Player ones Total Is Now " , p1_total)

    if p2_total % 2==0:
        print ("Player Two Got An Extra 10 Points For Getting An Even Number! ")
        p1_total = (p2_total) + 10
        print ("Player Twos Total Is Now " , p2_total)
    else:
        print ("Player Two Lost 5 Points For Getting An Odd Number! ")
        p1_total = (p1_total) - 5
        print ("Player Twos Total Is Now " , p2_total)
        
    if p1_total > p2_total:
        print ("Player 1 Won. Congratulations!!! ")
        difference = (p1_total) - (p2_total)
        print ("Player 2 was " , difference , " points away from drawing ")
    else:
        print ("Player 2 Won. Congratulations!!! ")
        difference = (p2_total) - (p1_total)
        print ("Player 1 was " , difference , " points away from drawing ")
    

Expected results are meant to be the difference between player one’s final score and player two’s final scores, but the code outputs a different number, never correct to the expected outcome.

Answers:

I believe you have a typo in your code and you are not actually updating your p2_total correctly. You are assigning the value to p1_total instead. Try changing the following lines:

if p2_total % 2==0:
    print ("Player Two Got An Extra 10 Points For Getting An Even Number! ")
    p2_total = (p2_total) + 10          # Renamed this line
    print ("Player Twos Total Is Now " , p2_total)
else:
    print ("Player Two Lost 5 Points For Getting An Odd Number! ")
    p2_total = (p2_total) - 5           # Renamed this line
    print ("Player Twos Total Is Now " , p2_total)
Answered By: K-Log
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.