CSCI 110, Spring 2011
Home | | Course Schedule | | Assignments | | Lecture Notes Homework 4 solutionSolution to price.py program:
# program price.py # Author: Brenda Student # Section: CSCI 110 # Date: February 22, 2011 # Purpose: Enter an inventory and a price. # Print out what can be bought for the given price. item=[] price=[] numItems = input("How many items are in the inventory? ") print for i in range(numItems): newItem = raw_input("Please enter the item name: ") item.append(newItem) newPrice = input("Please enter the price of the item: ") price.append(newPrice) print amount = input("How much would you like to spend? ") print print "The following can be bought for $%3.2f:"%amount for x in range(numItems): if price[x] <= amount: print "Item: "+ item[x] + ", Price: $%3.2f"%price[x]