Write a class GamingProfile with private attributes for game scores and achievements. Include methods to update these, making sure that the updates follow certain rules (e.g., scores only increasing).
Example 1:
Input: Update Score: 500 Output: "Score updated"
Example 2:
Input: Update Score: 300 Output: "Score cannot decrease"
Check the current score before updating.
class GamingProfile:
def __init__(self):
self._score = 0
self._achievements = []
def update_score(self, score):
if score >= self._score:
self._score = score
return "Score updated"
else:
return "Score cannot decrease"
def add_achievement(self, achievement):
self._achievements.append(achievement)
# Test the class
gaming_profile = GamingProfile()
gaming_profile.update_score(500) # Output: Score updated
gaming_profile.update_score(300) # Output: Score cannot decrease
Unlock AI & Data Science treasures. Log in!