I have a function that creates a player object but when referencing the object, I get a NameError. I think it is happening due to local scope but global should fix it...

I just started out OOP and this code is working in the python shell but it is not working in script mode.

```py
endl = lambda a: print("\n"*a)

class Score:
    _tie = 0
    def __init__(self):
        self._name = ""
        self._wins = 0
        self._loses = 0

    def get_name(self):
        print
        self._name = input().upper()

    def inc_score(self, wlt):
        if wlt=="w": self._wins += 1
        elif wlt=="l": self._loses += 1
        elif wlt=="t": _tie += 1
        else: raise ValueError("Bad Input")

def player_num(): #Gets number of players
    while True:
        clear()
        endl(10)
        print("1 player or 2 players?")
        endl(5)
        pnum = input('Enter 1 or 2: '.rjust(55))
        try:
            assert int(pnum) == 1 or int(pnum) == 2
            clear()
            return int(pnum)
        except:
            print("\n\nPlease enter 1 or 2.")

def create_player():  #Creates players
    global p1
    p1 = Score()
    yield 0          #stops here if there is only 1 player
    global p2
    p2 = Score()

def pr_():          #testing object
    input(p1._wins)
    input(p2._wins)

for i in range(player_num()):
    create_player()
    input(p1)
input(p1._wins())
pr_()

```

wherever I reference p1 I should get the required object attributes but I'm getting this error

```
Traceback (most recent call last):
  File "G:/Python/TicTacTwo.py", line 83, in <module>
    input(p1)
NameError: name 'p1' is not defined

```