[Solved] Why does this code not output the winner variable?


Try:

import random
class player:

    def __init__(self, name):
        self.name = name
        self.score = random.randint(1,6)
        print(self.name, self.score)

player_1 = player("Richard")
player_2 = player("Bob")
winner=""
if player_1.score > player_2.score:
    winner = player_1.score 
    print(winner)
elif player_2.score> player_1.score:
    winner = player_2.score 
    print(winner)
else:
    print("Tie.")

Output:
enter image description here

7

solved Why does this code not output the winner variable?