IB CS1 3rd Quarter Exam
From WLCS
Directions
- This exam is open-book, open-notes, closed-person.
- You are an avid Dungeons and Dragons player, but you have so many characters, you have a difficult time keeping track of them all! You must implement the following class and program for your D&D Character Database
Character class
Attributes:
- player name (string)
- character type (string examples fighter, thief, mage, cleric, paladin)
- level (0-10 int)
- health (0-100 int)
- weapon (string)
- attack strength (0-20 int)
- defense strength (0-20 int)
Methods:
- __init__() - should set all of the attributes
- __str__() - returns a string with the player's name and type
- Example: "Mr. Bui the level 10 paladin"
- attack() - returns a random number from 1 up to the player's attack strength
- defend() - returns a random number from 1 up to the player's defense strength
Randomizing:
- import random at the top
- random.randint(lower, upper)
Program
- Create an empty list named myCharacters
- Using a loop, display a menu that lets the user (a)dd, (r)emove, (s)earch, a(t)tack, (d)efend, (p)rint, (q)uit
- The (a)dd option should prompt the user for all the necessary attributes of a Character and then append one to the myCharacters list
- The (r)emove option should prompt the user for a name and remove the character
- The (s)earch option allows the user to search for the character and prints it out
- The a(t)tack option prompts the user for a character name and then runs its attack() method/function
- The (d)efend option prompts the user for a character name and then runs its defend() method/function
- The (p)rint option prints out ALL of the user's characters
- The (q)uit option breaks out of the menu's loop
Grading Rubric
- 3 pts - Character class correctly contains all necessary attributes
- 2 pts - __init__() method
- 2 pts - __str__() method
- 2 pts - attack() method
- 2 pts - defend() method
- 12 pts - Program (2 pts per option)