Exercise

Class-level attributes

Class attributes store data that is shared among all the class instances. They are assigned values in the class body, and are referred to using the ClassName. syntax rather than self. syntax when used in methods.

In this exercise, you will be a game developer working on a game that will have several players moving on a grid and interacting with each other. As the first step, you want to define a Player class that will just move along a straight line. Player will have a position attribute and a move() method. The grid is limited, so the position of Player will have a maximal value.

Instructions 1/2

undefined XP
    1
    2
  • Define a class Player that has:
  • A class attribute MAX_POSITION with value 10.
  • The __init__() method that sets the position instance attribute to 0.
  • Print Player.MAX_POSITION.
  • Create a Player object p and print its MAX_POSITION.