CSCI 110, Spring 2011
Home | | Course Schedule | | Assignments | | Lecture NotesDue Friday, February 25, at Noon
Introduction
In this assignment, you will write a program to aid a player in a text game who wishes to know
which
items for sale are within his or her price range. The player can type in the amount
he or she wishes to spend and the program will print out the name and price of each item
with a price that is less than or equal to that amount. The goal of this assignment is
to increase your familiarity with "for loops" and lists in python.
Program Description
The program will begin by creating two empty lists. One list, named item, will contain strings that
are the descriptions of the items for sale. The second list, named price, will contain real numbers
that are the prices of
those items. The lists will be set up so that the price of the first element in the item
list will be the first element of the price list. In other words, the price of item[0] will
be price[0], the price of item[1] will be price[1] and so on.
The program will start by having the user enter the items and prices into the two lists. The program should prompt the user for the number of items, and then read in each item and its price and add these to the appropriate lists (using the append( ) function). The program should then prompt the user for an amount that they wish to spend. Once the user has entered the amount, the program will print out the name and price of each item whose price is less than or equal to that amount.
Project Specifications
Specifications for Output.
Sample Run 1:
Sample Run 2:
To Submit Your Finished Project:
3. Hand in a printout of 2 sample runs like those shown above. Hand this to your
instructor in class on the project's due date.
4. Print your name at the top of the
cover page and staple it to the top of your hard copy.
5. In addition to the hard copy listed above, email your <username>_price.py file to
me at croyden@mathcs.holycross.edu
Get started early and have fun!
Place all your code in a file named <username>_price.py,
where
Directly below, you can see an example of the display that
will appear on the monitor screen for several sample runs of the program.
Underlined items indicate user input.
How many items are in the inventory? 4
Please enter the item name: potion
Please enter the price of the item: 2.75
Please enter the item name: lantern
Please enter the price of the item: 1.34
Please enter the item name: wand
Please enter the price of the item: 7.89
Please enter the item name: armor
Please enter the price of the item: 15.83
How much would you like to spend? 5.00
The following can be bought for $5.00:
Item: potion, Price: $2.75
Item: lantern, Price: $1.34
How many items are in the inventory? 3
Please enter the item name: Gold bars
Please enter the price of the item: 2000.32
Please enter the item name: sword
Please enter the price of the item: 10.56
Please enter the item name: magic staff
Please enter the price of the item: 15.99
How much would you like to spend? 50
The following can be bought for $50.00:
Item: sword, Price: $10.56
Item: magic staff, Price: $15.99
1. Hand in a hard copy of the file <username>_price.py. Hand this to your instructor
in class on the project's due date.