Difference between revisions of "Python - Descriptions module assignment"

From WLCS
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Objective ==
 
== Objective ==
* You will learn to create a module comprised of list variables and functions
+
You will learn to create a module comprised of list variables and functions
  
 
== Purpose ==
 
== Purpose ==
* The Descriptions module will allow us to generate a random adjective to describe a room ("dark", "haunted", etc.) and a random room type ("living room", "parlor", etc.), as well as random weapon names ("katana", "sai", etc.) and monster names ("goblin", "troll", etc.).
+
The Descriptions module will allow us to generate a random adjective to describe a room ("dark", "haunted", etc.) and a random room type ("living room", "parlor", etc.), as well as random weapon names ("katana", "sai", etc.) and monster names ("goblin", "troll", etc.).
  
 
== Directions ==
 
== Directions ==
Line 11: Line 11:
 
# Add 5 more values to each of the lists
 
# Add 5 more values to each of the lists
 
# Define the following functions:
 
# Define the following functions:
#* string getNextRoomAdjective() - returns a random adjective from the roomAdjectives list
+
#* string getNextRoomAdjective() - returns a random string from the roomAdjectives list
#* string getNextRoomType() - returns a random adjective from the roomTypes list
+
#* string getNextRoomType() - returns a random string from the roomTypes list
#* string getNextMonsterName() - returns a random adjective from the monsterNames list
+
#* string getNextMonsterName() - returns a random string from the monsterNames list
#* string getNextWeaponName() - returns a random adjective from the weaponNames list
+
#* string getNextWeaponName() - returns a random string from the weaponNames list
  
 
== Testing ==
 
== Testing ==
<syntaxhighlight lang="Python">
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
import descriptions
 
import descriptions
Line 23: Line 22:
 
for i in range(20):
 
for i in range(20):
 
     print("The " + descriptions.getNextRoomAdjective() + " " + descriptions.getNextRoomType() + " has a " + descriptions.getNextMonsterName() + " holding a " +descriptions.getNextWeaponName())
 
     print("The " + descriptions.getNextRoomAdjective() + " " + descriptions.getNextRoomType() + " has a " + descriptions.getNextMonsterName() + " holding a " +descriptions.getNextWeaponName())
</syntaxhighlight>
 
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 14:17, 9 May 2013

Objective

You will learn to create a module comprised of list variables and functions

Purpose

The Descriptions module will allow us to generate a random adjective to describe a room ("dark", "haunted", etc.) and a random room type ("living room", "parlor", etc.), as well as random weapon names ("katana", "sai", etc.) and monster names ("goblin", "troll", etc.).

Directions

  1. Download descriptions.py
  2. Examine the code in descriptions.py
    • There are four lists: room adjectives, room types, monster names, weapon names
  3. Add 5 more values to each of the lists
  4. Define the following functions:
    • string getNextRoomAdjective() - returns a random string from the roomAdjectives list
    • string getNextRoomType() - returns a random string from the roomTypes list
    • string getNextMonsterName() - returns a random string from the monsterNames list
    • string getNextWeaponName() - returns a random string from the weaponNames list

Testing

import descriptions

for i in range(20):
    print("The " + descriptions.getNextRoomAdjective() + " " + descriptions.getNextRoomType() + " has a " + descriptions.getNextMonsterName() + " holding a " +descriptions.getNextWeaponName())