Question

Problem 1 (Defining products and Creating a Menu) Write a program called a2_p1.py that asks a...

Problem 1 (Defining products and Creating a Menu)

Write a program called a2_p1.py that asks a shop owner for product information and creates a menu system that allows customers to purchase multiple products of varying quantities. The program should start by asking the shop owner’s name (string) and company name (string). Next it should ask for three (3) products (strings), their prices (int – not ideal, but for now we will keep it this way), and the number of products in stock (int). Finally, it should display a menu.

It is possible that the user will enter any type of data, including text, floating point numbers, negative numbers, etc.. Invalid selections should be handled with a suitable error messages and the menu should be repeated. Below is a sample run of the program that demonstrates how your output could look (user input is highlighted for emphasis): Sample output: Please enter your name: Alice What is your company name? Wonderland Hi Alice! Let's setup a sales menu for 'Wonderland'. Please enter the following information for Wonderland's products. Enter Product 1 information: Name: Cake Cake's Price: two Price must be a number, please enter again. Cake's Price: -2 Price must be a number, please enter again. Cake's Price: 2 How many Cake in stock: ten Enter again, stock must be a positive number. How many Cake in stock: -10 Enter again, stock must be a positive number. How many Cake in stock: 10 Enter Product 2 information: Name: Hat Hat's Price: 3 How many Hat in stock: 7 Enter Product 3 information: Name: Bunny Bunny's Price: 8 How many Bunny in stock: three each Enter again, stock must be a positive number. How many Bunny in stock: 3 Your menu: =================================== Please select the item you want to buy from the following menu: 1. Cake (each $2.00), 10 in stock 2. Hat (each $3.00), 7 in stock 3. Bunny (each $8.00), 3 in stock Press 4 when you are done! ===================================

Homework Answers

Answer #1

Short Summary:

  1. Implemented the program as per requirement
  2. Attached source code and sample output

**************Please do upvote to appreciate our time. Thank you!******************

Source Code:

class a2_p1(object):
def validateAndDisplayMenu(self,num): #function to prompt user and validate input
name = input("Please enter your name: ") #Ask user for name
companyName = input("What is your company name? ") #Ask user for company name
print("Hi ",name,"!","Let's setup a sales menu for '",companyName,"'.")
print("Please enter the following information for ",companyName,"'s products.")
prodList = [None] * num #create product list of product size
priceList= [None] * num #create price list of product size
stockList= [None] * num #create stock list of product size
for i in range(num): #loop number of product times
var = "Enter Product " +str(i+1) + " information: Name: "
prodName = input(var)
prodList[i]=prodName
valid=False
while valid==False: #loop until valid price is entered
var=prodName+"'s price:"
price=input(var)
if price.isnumeric() and int(price) > 0:
priceList[i]=price
valid=True
else:
print("Price must be a number, please enter again.")
valid=False
valid=False #reassign valid to false
while valid==False: #loop until valid stock is entered
var="How many "+prodName+" in stock:"
stock=input(var)
if stock.isnumeric() and int(stock) > 0:
stockList[i]=stock
valid=True
else:
print("Enter again.Stock must be a positive number")
valid=False
print("Your menu: =================================== Please select the item you want to buy from the following menu:")
for i in range(num):
print(i,". ",prodList[i],"(each $",priceList[i],")", stockList[i]," in stock")
print(" Press 4 when you are done! ===================================")
  
if __name__ == "__main__":
product=3
a2_p1().validateAndDisplayMenu(product)

Code Screenshot:

Output:


**************Please do upvote to appreciate our time. Thank you!******************

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I am looking for PYTHON code that will display the following: Code a menu-driven application that...
I am looking for PYTHON code that will display the following: Code a menu-driven application that does the following: The user can enter data for a product name, product code, and unit price. An example might be 'Breaburn Apples', 'BAP'. 1.99. After entering the data, it is appended (note I said 'appended') as a single line of text to a text file. Each line of text in the file should represent a single product. There is an option to display...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with four items. The user should then be prompted to make a selection from the menu and based on their selection the program will perform the selected procedure. The title and menu should be as the following: Student name: <your name should be printed> CIS 232 Introduction to Programming Programming Project 6 Due Date: October 23, 2020 Instructor: Dr. Lomako ******************************** 1.     Compute Angles                               *...
Write a C++ program to run a menu-driven program with the following choices: Compute the factorial...
Write a C++ program to run a menu-driven program with the following choices: Compute the factorial of a number Compute the alternating factorial of a number Quit #include <iostream> using namespace std; void getValidUserInputPosNumGT0 (int *a) { int num; cout << "Enter in a positive number greater than 0... "; cin >> *a; } long double factorial (int num) { int fact = 1; while (num > 1) { fact *= num; num--; } return fact; } long double AlternatingFactorial...
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter an number. Then, it asks for a second number. These will use the "input" command. Store these as two separate variables. This function takes NO arguments and is also a VOID function, there is no return statement. The function should print the result of these two numbers multiplied together. The program should be able to multiply floats. For example: Test Input Result calculateInput() 5...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character ‘X’. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following:       XXXXX       XXXXX       XXXXX       XXXXX       XXXXX INPUT and PROMPTS. The program prompts for an integer as follows: "Enter...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2. Calculate Current in Amps 3. Calculate Voltage in volts 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula: R= E/i Where: E= voltage in volts I= current in amps R= resistance in ohms If the user enters 2 the program should ask for the voltage...
Problem 1. Your company is creating product code for its product control. They need you to...
Problem 1. Your company is creating product code for its product control. They need you to figure out some stuff If the code consists of 3 small letters from our English alphabet followed by a dash, and then 4 numbers followed by a dash and then followed by 2 letters (again small English alphabet), please answer the following important cooperate questions . _ _ _ - _ _ _ _ - _ _ (a) How many different product codes are...
Write a program in Java that: 1. will prompt user with a menu that contains options...
Write a program in Java that: 1. will prompt user with a menu that contains options to: a. Add a To-Do Item to a todo list. A To-Do Item contains: i. An arbitrary reference number (4; 44,004; etc.) ii. A text description of the item ("Pick up dry cleaning", etc.) iii. A priority level (1, 2, 3, 4, or 5) b. View an item in the list (based on its reference number) c. Delete an item from the list (based...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT