Question

In Python please. Problem 3 (Tracking Stock Levels) For this third part, you will add functionality to track stock level...

In Python please.

Problem 3 (Tracking Stock Levels)
For this third part, you will add functionality to track stock levels within the store and prevent
customers from placing orders that cannot be fulfilled. Again, copy your solution from the
previous problem into a new file called a2p3.py. Do not overwrite your previous solution, as
the TAs will want to see them both.
Modify your code by adding a new variable to keep track of the stock level of each product in
the store. The initial stock quantity of each product should be 15. Update your menu display to
include the stock levels of each product. Whenever a customer successfully selects a product
and specifies an acceptable amount, the stock level should be decreased by the amount the
customer has selected. If there is not enough stock to fulfill the request, the customer should
receive a message indicating this and the menu should be printed again (similar to an incorrect
input scenario).

Below is a sample run of the program that demonstrates how your output could look (user input
is highlighted for emphasis):
>python a2p3.py
Welcome, to Buy-nary Computing!
Please enter your name to begin: Andrew
Please select a product from the following menu:
1. Desktop Computer ($850 each, 15 in stock)
2. Laptop Computer ($1225 each, 15 in stock)
3. Tablet ($600 each, 15 in stock)
4. Toaster Oven ($85 each, 15 in stock)
5. Complete Order
> 1
How many Desktop Computers would you like to purchase? 12
Please select a product from the following menu:
1. Desktop Computer ($850 each, 3 in stock)
2. Laptop Computer ($1225 each, 15 in stock)
3. Tablet ($600 each, 15 in stock)
4. Toaster Oven ($85 each, 15 in stock)
5. Complete Order
> 4
How many Toaster Ovens would you like to purchase? 3
Please select a product from the following menu:
1. Desktop Computer ($850 each, 3 in stock)
2. Laptop Computer ($1225 each, 15 in stock)
3. Tablet ($600 each, 15 in stock)
4. Toaster Oven ($85 each, 12 in stock)
5. Complete Order
> 1
How many Desktop Computers would you like to purchase? 4
Sorry, we don’t have that many Desktop Computers.
Please select a product from the following menu:
1. Desktop Computer ($850 each, 3 in stock)
2. Laptop Computer ($1225 each, 15 in stock)
3. Tablet ($600 each, 15 in stock)
4. Toaster Oven ($85 each, 12 in stock)
COMP 1005/1405A – S19 – A2 Due Saturday, May 25th at 11:59 PM
6
5. Complete Order
> 5
Andrew, here is your receipt:
-------------------------------------
12 Desktop computers
3 Toaster Ovens
-------------------------------------
Total cost: 10455.00
Thank you, have a nice day!

Here's the code:

#inputs

Devices = ["Desktop Computers", "Laptop Computers", "Tablets", "Toaster Ovens"]
DevicesPrices = [850, 1225, 600, 85]
DeviceQua = [0, 0, 0, 0]

print("Welcome, to Buy-nary Computing!")
name = input("Please enter your name to begin: ")

while(True):
    print("Please select a product from the following menu: ")
    print("1. Desktop Computer ($850 each)")
    print("2. Laptop Computer ($1225 each)")
    print("3. Tablet ($600 each)")
    print("4. Toaster Oven ($85 each)")
    print("5. Complete order.")

    selection = int(input("> "))

    if(selection <= 5 and selection > 0):
        if selection == 1:
            many = int(input("How many Desktop Computers would you like to purchase? "))
            DeviceQua[0] += many

        elif(selection == 2):
            many = int(input("How many Laptop Computers would you like to purchase? "))
            DeviceQua[1] += many

        elif(selection == 3):
            many = int(input("How many Tablets would you like to purchase? "))
            DeviceQua[2] += many

        elif(selection == 4):
            many = int(input("How many Toaster Ovens would you like to purchase? "))
            DeviceQua[3] += many
        elif(selection == 5):
            break
    else:
        print("I'm sorry, that's not a valid selection. Please enter a selection from 1-5.")

total_price = 0
for i in range(0,4):
total_price += float(DevicesPrices[i] * DeviceQua[i])

print(name, ", here is your receipt:")
print("-------------------------------")
for x in range(0, 4):
    if DeviceQua[x] != 0:
        print(DeviceQua[x].__str__() + " " + Devices[x])
print("-------------------------------")
print("Total Cost : $" + total_price.__str__())
print("Thank you, have a nice day ^^")

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

#inputs 2 Devices [Desktop Computers, Laptop Computers,Tablets, Toaster Ovens 3 DevicesPrices [850, 1225, 600, 85] 4

else: print( Sorry, we dont have that many Desktop Computers. 23 24 elif(selection 2): 25 int (input( How many Laptop Comp

DeviceQua[3]many DeviceStock[3] -many 45 46 else: print( Sorry, we dont have that many Toaster Ovens.) 47 elif(selection =

Code:

#inputs

Devices = ["Desktop Computers", "Laptop Computers", "Tablets", "Toaster Ovens"]

DevicesPrices = [850, 1225, 600, 85]

DeviceQua = [0, 0, 0, 0]

DeviceStock = [15, 15, 15, 15]

print("Welcome, to Buy-nary Computing!")

name = input("Please enter your name to begin: ")

while(True):

print("Please select a product from the following menu: ")

print("1. Desktop Computer ($850 each, %d in stock)"%DeviceStock[0])

print("2. Laptop Computer ($1225 each, %d in stock)"%DeviceStock[1])

print("3. Tablet ($600 each, %d in stock)"%DeviceStock[2])

print("4. Toaster Oven ($85 each, %d in stock)"%DeviceStock[3])

print("5. Complete order.")

selection = int(input("> "))

if(selection <= 5 and selection > 0):

if selection == 1:

many = int(input("How many Desktop Computers would you like to purchase? "))

if(DeviceStock[0]>many):

DeviceQua[0] += many

DeviceStock[0] -= many

else:

print("Sorry, we don’t have that many Desktop Computers.")

elif(selection == 2):

many = int(input("How many Laptop Computers would you like to purchase? "))

if(DeviceStock[1]>many):

DeviceQua[1] += many

DeviceStock[1] -= many

else:

print("Sorry, we don’t have that many Laptop Computers.")

elif(selection == 3):

many = int(input("How many Tablets would you like to purchase? "))

if(DeviceStock[2]>many):

DeviceQua[2] += many

DeviceStock[2] -= many

else:

print("Sorry, we don’t have that many Tablets.")

elif(selection == 4):

many = int(input("How many Toaster Ovens would you like to purchase? "))

if(DeviceStock[3]>many):

DeviceQua[3] += many

DeviceStock[3] -= many

else:

print("Sorry, we don’t have that many Toaster Ovens.")

elif(selection == 5):

break

else:

print("I'm sorry, that's not a valid selection. Please enter a selection from 1-5.")

total_price = 0

for i in range(0,4):

total_price += float(DevicesPrices[i] * DeviceQua[i])

print(name, ", here is your receipt:")

print("-------------------------------")

for x in range(0, 4):

if DeviceQua[x] != 0:

print(DeviceQua[x].__str__() + " " + Devices[x])

print("-------------------------------")

print("Total Cost : $" + total_price.__str__())

print("Thank you, have a nice day ^^")

Add a comment
Know the answer?
Add Answer to:
In Python please. Problem 3 (Tracking Stock Levels) For this third part, you will add functionality to track stock level...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python and in one file please. (Simple functions with an expressions) Create a function called...

    In Python and in one file please. (Simple functions with an expressions) Create a function called load_inventory(filename). The filename argument in this case specifies the name of a file that contains all the inventory/product information for the store, including product names, descriptions, prices, and stock levels. This function should clear any information already in the product list (i.e., a fresh start) and then re-initialize the product list using the file specified by the filename argument. You can structure your file...

  • In Python and in one file please. (Simple functions with an expressions) Create a function called load_inventory(filenam...

    In Python and in one file please. (Simple functions with an expressions) Create a function called load_inventory(filename). The filename argument in this case specifies the name of a file that contains all the inventory/product information for the store, including product names, descriptions, prices, and stock levels. This function should clear any information already in the product list (i.e., a fresh start) and then re-initialize the product list using the file specified by the filename argument. You can structure your file...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

  • Coding for Python - The pattern detection problem – part 3: def pattern_search_max(data_series, pattern, threshold) Plea...

    Coding for Python - The pattern detection problem – part 3: def pattern_search_max(data_series, pattern, threshold) Please do not use 'print' or 'input' statements. Context of the assignment is: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below: We need to consider the following cases: Case 1 - It is possible that the...

  • Coding for Python - The pattern detection problem – part 2: def calculate_similarity_list(data_series, pattern) Please do not use 'print' or 'input' statements. Context of the assignme...

    Coding for Python - The pattern detection problem – part 2: def calculate_similarity_list(data_series, pattern) Please do not use 'print' or 'input' statements. Context of the assignment is: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below: We need to consider the following cases: Case 1 - It is possible that the given...

  • Please use own words. Thank you. CASE QUESTIONS AND DISCUSSION > Analyze and discuss the questions...

    Please use own words. Thank you. CASE QUESTIONS AND DISCUSSION > Analyze and discuss the questions listed below in specific detail. A minimum of 4 pages is required; ensure that you answer all questions completely Case Questions Who are the main players (name and position)? What business (es) and industry or industries is the company in? What are the issues and problems facing the company? (Sort them by importance and urgency.) What are the characteristics of the environment in which...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT