Question: Write Code in Python class SodaMachine: ''' Creates instances of the class SodaMachine. Takes a string and an integer >>> m = SodaMachine('Coke', 10) >>>

Write Code in Python

Write Code in Python class SodaMachine: ''' Creates instances of the class

class SodaMachine:

'''

Creates instances of the class SodaMachine. Takes a string and an

integer

>>> m = SodaMachine('Coke', 10)

>>> m.purchase()

'Product out of stock'

>>> m.restock(2)

'Current soda stock: 2'

>>> m.purchase()

'Please deposit $10'

>>> m.deposit(7)

'Balance: $7'

>>> m.purchase()

'Please deposit $3'

>>> m.deposit(5)

'Balance: $12'

>>> m.purchase()

'Coke dispensed, take your $2'

>>> m.deposit(10)

'Balance: $10'

>>> m.purchase()

'Coke dispensed'

>>> m.deposit(15)

'Sorry, out of stock. Take your $15 back'

'''

def __init__(self, product, price):

#-- start code here ---

#-- ends here ---

def purchase(self):

#-- start code here ---

#-- ends here ---

def deposit(self, amount):

#-- start code here ---

#-- ends here ---

def restock(self, amount):

#-- start code here ---

#-- ends here ---

[5 pts] Write the class SodaMachine that will represent a typical soda vending machine (product name, price). An instance of SodaMachine has access to three methods, purchase, deposit and restock that will describe its interaction with the user returning strings. Tip: use the string format method >>m-SodaMachine 'Coke, 10) >>>m.purchase () Product out of stock' >>> m.restock (2) Current soda stock: 2' >>>m.purchase () Please deposit $10" >>> m.deposit(7) Balance: $7 >>>m.purchase () Please deposit $3' >>> m.deposit (5) Balance: $12' >>>m.purchase () 'Coke dispensed, take your $2' >>> m.deposit (10) Balance: $10' >>>m.purchase () 'Coke dispensed' >>> m.deposit (15) Sorry, out of stock. Take your $15 back' >>> x= SodaMachine ('Dr. Pepper', 8) >>>x.restock (1) Current soda stock: 1' >>>x.deposit (8) Balance: $8' >>>x.purchase () Dr. Pepper dispensed' Quotes mean method returned a string, no need to append them in your code Return output with the sentences provided. Solution is not case or space sensitive, which means Balance: $10 is the same as balance:S10, but is not the same as Balance- $10 e

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 Databases Questions!