Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Read the entire assignment carefully before beginning. In this assignment, you’r

ID: 670122 • Letter: R

Question

Read the entire assignment carefully before beginning. In this assignment, you’re going to develop a simulated community message board where users can post items they have for sale or search for items they want to buy. Your program will search for matches, e.g. there is a bike for sale for $50 and a bike wanted, where the buyer will pay up to $60, and remove items from the message board as they are sold. Users have the option of posting and searching for as many items as they choose before they quit the program.

Getting started Your program should display a menu with the following selections: 1. Add an item. 2. Find an item. 3. Print the message board. 4. Quit. Use the following python print and input statements for your menu: print "1. Add an item." print "2. Find an item." print "3. Print the message board." print "4. Quit." choice = input("Enter your selection:") This menu should be displayed after every transaction is complete unless the user selects Quit. The user can select the option they want using the number for the option. For example, to add an item, they type 1.

Add an item If the user selects 1 to add an item, they should be prompted for the type of item to add and the cost of the item. To simplify the program, there are five types of items: bike, microwave, dresser, truck and chicken. Your input prompts, either input() or raw_input(), need to include the exact text shown here: "Enter the item type-b,m,d,t,c:" "Enter the item cost:" The user types the first letter of the item type to indicate the type they want to add. Data in the message board is stored as a list of lists. Each element on the message board is a list that contains the type and the cost, and all of the individual elements are stored in the message board list. Your list will look something like this: [[‘bike’, 50], [‘truck’, 1000], [‘microwave’, 10]] In this example, there are three elements in the message board list, a bike for $50, a truck for $1000, and a microwave for $10. The first element in the message board list is a list with two elements: the string “bike” and the integer 50, which is the cost. Each of the individual lists in the message board has two properties, a string and an integer. When an element is added to the message board list, it should be appended to the end of the list. Don’t sort the data, COG will be expecting your data to be stored in the order it is added. Duplicates are also okay.

Find an item When the user selects 2 to find an item, they should be prompted with the item type, and the maximum price they are willing to pay for the item. Your code should then search the list and return the first item with the correct type and a cost that is less than or equal to the price that the user will pay. Use the following text in your prompts: "Enter the item type-b,m,d,t,c:" "Enter the maximum item cost:" For example, if the user types b and 50, they want a bicycle and are willing to pay up to $50 for it. Your program should find the first bicycle in the list that sells for $50 or less. If a match is found, print “Sold for” Use the following print statement: print "Sold", itemType, "for", itemCost where itemType and itemCost are variables that store the type of the item and its cost. The itemType is one of the following: bike, microwave, dresser, truck, or chicken. The itemCost is the actual item cost, not what the user is willing to pay. The item should then be removed from the list. If the item is not found, do nothing.

Print the message board If the user selects Print the message board, your program should display the items in the message board list in the following format: : Use the following print statement to generate the output: print itemType, ": ",itemCost

Quit If the user selects 4 for Quit, the program should exit the while loop that controls the program, which will cause the program to exit.

Explanation / Answer

n=0
itemList=[0]*100
l=[0]*2
t=[0]*2

count=0
while n==0:
print "1.Add an item"
print "2.Find an item"
print "3.Print the message board"
print "4.Quit."
choice=input("Enter your selection: ")
if choice==1:
itemType=raw_input("enter the item type-b,m,d,t,c:")
itemCost=int(raw_input("enter the item cost"))
if itemType=="b":
l[0]="bike"
if itemType=="m":
l[0]="microwave"
if itemType=="d":
l[0]="dresser"
if itemType=="t":
l[0]="truck"
if itemType=="c":
l[0]="chicken"
l[1]=itemCost
itemList[count]=l[:]
count=count+1
print itemList
  
if choice==2:
itemType=raw_input("enter the item type-b,m,d,t,c:")
itemCost=int(raw_input("enter the maximum item cost: "))
if itemType=="b":
t[0]="bike"
if itemType=="m":
t[0]="microwave"
if itemType=="d":
t[0]="dresser"
if itemType=="t":
t[0]="truck"
if itemType=="c":
t[0]="chicken"
t[1]=itemCost
for i in range(0,len(itemList)):
if itemList[i][0]==t[0]:
if itemList[i][1]<=t[1]:
print itemList
print "Sold", t[0], "for", itemList[i][1]
del(itemList[i])
count=count-1
break
if choice==3:
for i in range(0,len(itemList)):
print itemList[i][0], ":%s ",str(itemList[i][1])
if choice==4:
break
  
  
  
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote