PROBLEM 4 Here is the e-list for Mart 007 ------------------ Welcome ------------------ ============================================= Please select the item you want to buy from the following menu: 1. Spiked Umbrella ($7.25 each), 5 available 2. Voice Changer ($5.5 each), 10 available 3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! ============================================= Using python, write a function named transaction() that repeatedly shows the e-list for Mart 007 to a user so that users can choose the products and the quantities they want to buy. All user inputs must be validated. At every iteration, the inventory should be updated until the user decides to quit. That means the values stored in your data structures need to be updated. Your function must use exception handling to handle all possible run-time errors so this function does not crash. Sample output: ------------------ Welcome ------------------ ============================================= Please select the item you want to buy from the following menu: 1. Spiked Umbrella ($7.25 each), 5 available 2. Voice Changer ($5.5 each), 10 available 3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! ============================================= Select product >> 1 You have selected the Spiked Umbrella, how many would you like to buy? >> 2 2 Spiked Umbrella(s) have been selected. Current total is $14.5. ============================================= Please select the item you want to buy from the following menu: 1. Spiked Umbrella ($7.25 each), 3 available 2. Voice Changer ($5.5 each), 10 available 3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! ============================================= Select product >> 2 You have selected the Voice Changer, how many Quantity must be a number. Please enter again Quantity must be positive. Please enter again 3 Voice Changer(s) have been selected. Current total is $31.0. ============================================= Please select the item you want to buy from the following menu: 1. Spiked Umbrella ($7.25 each), 3 available 2. Voice Changer ($5.5 each), 7 available 3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! ============================================= would you like to buy? >> three >> -3 >> 3 Select product >> 1 You have selected the Spiked Umbrella, how many would you like to buy? >> 4 Sorry, only 3 Spiked Umbrella(s) are available in stock. Please lower the quantity or try a different item. ============================================= Please select the item you want to buy from the following menu: 1. Spiked Umbrella ($7.25 each), 3 available 2. Voice Changer ($5.5 each), 7 available 3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! ============================================= Select product >> 1 You have selected the Spiked Umbrella, how many would you like to buy? >> 1 1 Spiked Umbrella(s) have been selected. Current total is $38.25. ============================================= Please select the item you want to buy from the following menu: 1. Spiked Umbrella ($7.25 each), 2 available 2. Voice Changer ($5.5 each), 7 available 3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! ============================================= Select product >> 3 You have selected the Spy Camera, how many would you like to buy? >> 2 2 Spy Camera(s) have been selected. Current total is $68.25. ============================================= Please select the item you want to buy from the following menu: 1. Spiked Umbrella ($7.25 each), 2 available 2. Voice Changer ($5.5 each), 7 available 3. Spy Camera ($15.0 each), 6 available Press 4 when you are done! ============================================= Select product >> 4 Thank You!
PROBLEM 4
Here is the e-list for Mart 007
------------------ Welcome ------------------ =============================================
Please select the item you want
to buy from the following menu:
1. Spiked Umbrella ($7.25 each), 5 available 2. Voice Changer ($5.5 each), 10 available
3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! =============================================
Using python, write a function named transaction() that repeatedly shows the e-list for Mart 007 to a user so that users can choose the products and the quantities they want to buy. All user inputs must be validated. At every iteration, the inventory should be updated until the user decides to quit. That means the values stored in your data structures need to be updated. Your function must use exception handling to handle all possible run-time errors so this function does not crash.
Sample output:
------------------ Welcome ------------------ =============================================
Please select the item you want
to buy from the following menu:
1. Spiked Umbrella ($7.25 each), 5 available 2. Voice Changer ($5.5 each), 10 available
3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! =============================================
Select product >> 1
You have selected the Spiked Umbrella, how many would you like to buy? >> 2
2 Spiked Umbrella(s) have been selected.
Current total is $14.5. =============================================
Please select the item you want
to buy from the following menu:
1. Spiked Umbrella ($7.25 each), 3 available 2. Voice Changer ($5.5 each), 10 available
3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! =============================================
Select product >> 2
You have selected the Voice Changer, how many Quantity must be a number. Please enter again Quantity must be positive. Please enter again
3 Voice Changer(s) have been selected.
Current total is $31.0. =============================================
Please select the item you want
to buy from the following menu:
1. Spiked Umbrella ($7.25 each), 3 available 2. Voice Changer ($5.5 each), 7 available
3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! =============================================
would you like to buy? >> three >> -3
>> 3
Select product >> 1
You have selected the Spiked Umbrella, how many would you like to buy? >> 4 Sorry, only 3 Spiked Umbrella(s) are available in stock.
Please lower the quantity or try a different item. =============================================
Please select the item you want
to buy from the following menu:
1. Spiked Umbrella ($7.25 each), 3 available 2. Voice Changer ($5.5 each), 7 available
3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! =============================================
Select product >> 1
You have selected the Spiked Umbrella, how many would you like to buy? >> 1
1 Spiked Umbrella(s) have been selected.
Current total is $38.25. =============================================
Please select the item you want
to buy from the following menu:
1. Spiked Umbrella ($7.25 each), 2 available 2. Voice Changer ($5.5 each), 7 available
3. Spy Camera ($15.0 each), 8 available Press 4 when you are done! =============================================
Select product >> 3
You have selected the Spy Camera, how many would you like to buy? >> 2
2 Spy Camera(s) have been selected.
Current total is $68.25. =============================================
Please select the item you want
to buy from the following menu:
1. Spiked Umbrella ($7.25 each), 2 available 2. Voice Changer ($5.5 each), 7 available
3. Spy Camera ($15.0 each), 6 available Press 4 when you are done! =============================================
Step by step
Solved in 3 steps with 2 images