Build a Player Class with Score Tracking
Intermediate · Write the code · from Python Classes and Objects: OOP from the Ground Up
From the lesson: Python Classes and Objects: OOP from the Ground Up
Imagine you own a bakery and you have a cookie cutter shaped like a star. Every time you press it into dough, you get a new star-shaped cookie. The cutter itself isn't a cookie - it's a blueprint for making cookies.
Read the lessonCreate a Player class with:
total_players starting at 0__init__ takes name and sets self.score = 0, and increments Player.total_playerswin_round(self, points) method that adds points to self.scoreCreate two players 'Alice' and 'Bob'. Alice wins a round with 10 points, then Bob wins with 15 points. Print each player's score and the total number of players in this exact format:
Alice: 10
Bob: 15
Total players: 2# Create your Player class here
More Classes and Objects exercises
- Create a Book ClassBeginner
- Add a Method to RectangleBeginner
- Predict the Counter OutputBeginner
- Fix the Student ClassIntermediate
- Add __str__ to a ProductIntermediate
- Refactor Functions into a ClassAdvanced
All Python exercises · 50 practice problems · Object-Oriented Programming quiz