A stamp card with a reward for ten stamps
Write code · Challenge · §11.3 Methods that change state
Write a class StampCard for a cafe stamp card. When you create a card with StampCard(owner), it stores the name in the attribute owner, and the stamp count stamps starts at 0.
add(n) adds n stamps. If n is 0 or less, it changes nothing.
redeem() uses up 10 stamps and returns True if there are 10 or more. If there are not enough, it changes nothing and returns False.
need() returns how many more stamps are needed for the next reward. If the card already has 10 or more stamps, it returns 0. It does not change the stamp count.
Starter code
class StampCard:
# Write __init__, add, redeem, and need here
pass
card = StampCard("mina")
card.add(4)
card.add(7)
print(card.redeem(), card.stamps, card.need())Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.