MONT 105S, Spring 2009

Home | | Course Schedule | | Assignments | | Lecture Notes

MONT 105S Homework 11

How Much Can You Buy for a Dollar?

Due Friday, March 13, at the beginning of class.

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
Place all your code in a file named <username>_price.py, where refers to your own username. For example, Professor Royden's file would be named croyden_price.py.

  1. Create variables for the two lists and assign an empty list to each of them.
  2. Prompt the user to enter the number of items in the inventory.
  3. Use a for loop to enter each item and its price and add them to the appropriate lists.
  4. Prompt the user to enter the amount he or she wishes to spend and read it in.
  5. Based on the amount, the computer should list the name and price of every item whose price is less than or equal to the amount entered by the user. You should use a for loop to accomplish this.
  6. Write your code to assure that the text that appears on the monitor looks like that displayed in the section below.

Specifications for Output.
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.