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

Note that the programs you will be writing for Part2a through Part 2f build on o

ID: 3766712 • Letter: N

Question

Note that the programs you will be writing for Part2a through Part 2f build on one another. You will want to attempt these parts in order. You can also feel free to save all of your work in one big file (call it "LastNameFirstName_assign8_part2.py")

Imagine that you are helping to build a store management system for a fast food restaurant. Given the following lists, write a program that asks the user for a product name. Next, find out if the restaurant sells that item and report the status to the user. Allow the user to continually inquire about product names until they elect to quit the program.

Here are some lists to get you started:

And here's a sample running of your program:

Explanation / Answer

Here is the code for you. If you have any futher queries, just get back to me.

#! /usr/bin/python
# product lists
product_names = ["hamburger", "cheeseburger", "small fries"]
product_costs = [0.99, 1.29, 1.49]
choice = 's'
while(choice == 's'):
choice = raw_input('(s)earch for product or (q)uit: ');
if(choice == 'q'):
break;
elif(choice != 's'):
print 'Invalid option, try again'
else:
productName = raw_input('Enter a product name: ');
index = product_names.index(productName) if productName in product_names else -1;
if(index == -1):
print ('Sorry, we don''t sell '+productName)
else:
print 'We sell "'+productName+'" at ',product_costs[index],' per unit'
  
  

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