Question: write a Python program that resembles some functions of a vending machine. This assignment will assess, as well as assist you to review, your acquired

write a Python program that resembles some functions of a vending machine. This assignment will assess, as well as assist you to review, your acquired Python knowledge and coding ability to solve a business problem.
A vending machine, which accepts only three denominations (i.e., fifty-cent, one-dollar, two- dollar), has five different products. The table below lists these products, their corresponding symbols and prices.
Product List
Product. symbol. Price
Soft Drink. s $ 3.0
Iced Coffee. c. $4.0
Energy Drink. e. $3.5
Water. w. $2.0
Green Tea. t. $2.5
Fresh Juice. fj. 5.0
Each time the user selects a symbol which represents a product and the vending machine will display the price of the chosen product. The user then inserts the coin, one at a time, until it
reaches or exceeds the displayed price. The vending machine then returns the change (if any) to the user.
This assignment consists of two parts.
Part I
The first part of this assignment focuses on the functionality of the vending machine. It requires you write a python script to replicate the above process by following steps below:
1. Print a menu which includes all above products with their symbols and prices.
2. Prompt the message: Please choose the symbol: and display the price of the
product after the user enters the symbol. For example, if the user selects w, then your program should display: The price of Water is $2.0.
3. Next, your program should repeat the following process until the paid price is larger than or equal to the displayed price:
1) 2)
4.
1)
2)
Prompt to the user: Please insert a coin of 50c, $1, or $2:
Print the outstanding amount after the user enter the coin as: The outstanding
amount is: x dollar x cents (where x is the actual amount) Finally, print out one of the following message:
'You paid the exact amount, Thanks' if no change need to be refunded
'Please take the following change: x dollars
x cents'
(where x is the actual amount) if there is any change to be returned.
To simplify the process, you may assume there are sufficient coins and drinks in the vending machine. In the first part, we may also assume that the user will not enter any invalid input.
Part II
In the second part, you will refine the Python script that you have completed in Part I to
handle some invalid inputs. There are three types of invalid inputs need to pick up:
1. Change the prompt message in Step 2 of Part I to: Please choose the symbol or select "q" to quit:. If the user selects q, then your program should terminate. If the user did not select q or any other symbol for the product, your program should print: Invalid Input, please try again! and then print the message: Please choose the symbol or select "q" to quit: again. Write a Python function to achieve this.
2. If the user enter a coin other than fifty-cent, one-dollar, or two-dollar, then print the following two messages:
'Only accept 50 cent, 1 dollar and 2 dollar coins.' 'Please enter 0.5, 1 or 2.'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!