Difference between revisions of "IB CS1 3rd Quarter Exam"

From WLCS
(New page: === 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 ...)
 
Line 26: Line 26:
 
=== Program ===
 
=== Program ===
 
# Create an empty list named myCharacters
 
# Create an empty list named myCharacters
# Display a menu that lets the user (a)dd, (r)emove, (s)earch, a(t)tack, (d)efend
+
# Display a menu that lets the user (a)dd, (r)emove, (s)earch, a(t)tack, (d)efend, (p)rint
 
#* 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 (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 (r)emove option should prompt the user for a name and remove the character
Line 32: Line 32:
 
#* The a(t)tack option prompts the user for a character name and then runs its attack() method/function
 
#* 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 (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

Revision as of 10:21, 22 March 2010

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

  1. Create an empty list named myCharacters
  2. Display a menu that lets the user (a)dd, (r)emove, (s)earch, a(t)tack, (d)efend, (p)rint
    • 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