Question: Python Optional / Bonus Task: Office Snack Stock Tracker This is a bonus question. Successfully completing this problem can earn you an additional 5 points.
PythonOptionalBonus Task: Office Snack Stock Tracker
This is a bonus question. Successfully completing this problem can earn you an additional
points. Not completing it will not affect your Project grade.
Scenario:
The office snack pantry is running low, and it's your job to track the snack stock levels.
Employees can check how many snacks are available, take snacks, or restock them. You
need to write a Python program to help manage the office snacks.
Requirements:
Snack List List:
Create a list of available snacks with initial quantities eg "Chips: "Cookies:
Check Snack Stock Loops and Lists:
Allow the user employee to check how many of each snack is available.
Take Snacks Conditions and Lists:
Allow the user to take snacks. Reduce the quantity of the chosen snack.
Restock Snacks Functions:
Create a function to restock snacks by adding to the current quantity.
Snack Usage Tracking Mathematical Functions:
Calculate how many snacks were taken and display the total number taken during
the session.
Example Output:
Welcome to the Office Snack Stock Tracker!
Available snacks:
Chips:
Cookies:
Candy:
Would you like to take a snack or restock? takerestockcheckexit: take
Which snack would you like? Chips
How many Chips would you like? You have taken Chips.
Available snacks:
Chips:
Cookies:
Candy:
Would you like to take a snack or restock? takerestockcheckexit: exit
Total snacks taken today:
Hints for Each Step:
Step : Snack List List
Hint:
Youll need a list or dictionary to store the snacks and their quantities.
A dictionary might be a better choice, as it allows you to pair each snack with its
available amount, like this:
Eg: snacks Chips: "Cookies": "Candy":
Step : Check Snack Stock Loops and Lists
Hint:
Use a for loop to go through the snack dictionary and print the snack name and
quantity.
You can loop through the dictionary like this:
eg: for snack, qty in snacks.items:
printfsnack: qty
Step : Take Snacks Conditions and Lists
Hint:
Ask the user which snack they want and how many they would like to take.
First, check if the snack exists in your list if snack in snacks:
Then, check if there are enough snacks available if amount snackssnack:
Subtract the amount taken from the snacks quantity.Step : Restock Snacks Functions
Hint:
Define a function that takes the snack name and the amount to restock as inputs.
Inside the function, add the restock amount to the current snack quantity:
eg: def restocksnack amount:
snackssnack amount
Step : Snack Usage Tracking Mathematical Functions
Hint:
Create a variable totaltaken and initialize it at
Each time a snack is taken, add the amount taken to this variable to keep track of
how many snacks have been consumed in total.
eg: totaltaken amount
Step : Main Loop User Interaction
Hint:
Use a while loop to keep the program running until the user types "exit."
Inside the loop, ask the user what they want to do eg take a snack, restock,
check, or exit
Use if elif, and else statements to handle the different actions based on the users
input.
Step : Exit and Show Total Snacks Taken
Hint:
When the user types "exit", break out of the loop.
Print the total number of snacks taken during the session by displaying the
totaltaken variable:
eg: printfTotal snacks taken today: totaltaken
Additional Tips:
User Input Validation:
If the user tries to take more snacks than available, let them know and dont allow
the action Case Sensitivity:
To make the program userfriendly, convert user input to lowercase or capitalize it
where necessary so its easier to match snack names.
Error Handling:
Consider adding a check for invalid inputs eg when a snack isnt in the list You
can use an else statement to handle this.
Improve Readability:
Use comments throughout your code to explain what each section does. This
makes the code easier to follow, especially for beginners.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
