Change method set_amount,then it should work:
Double underscores
Not your fault but your teacher who comes from a Java/C++ background,
and do it in a same as those languages in Python.
So could look like this:
def set_amount (self, value): self.__amount += valueThe getters/setters and
__
(which is not private),could be removed.Double underscores
__
is used for name mangling,nothing is really private in Python.Not your fault but your teacher who comes from a Java/C++ background,
and do it in a same as those languages in Python.
So could look like this:
import random class Coin: def __init__ (self, amount=20, sideup="Heads"): self.sideup = sideup self.amount = amount def toss(self): val = random.randint(0,1) if val == 0: self.sideup = "Heads" else: self.sideup = "Tails" c1 = Coin() c2 = Coin() play = input('Do you want to play? (Y/N): ') while play.lower() == 'y': c1.toss() c2.toss() if c1.sideup == c2.sideup: c1.amount += 5 c2.amount -= 5 print("player 1 wins") else: c1.amount -= 5 c2.amount += 5 print("player 2 wins") print(f'player1: {c1.amount} and player2: {c2.amount}') play = input("Do you want to play? (y/n): ")