Question: Python Help !!!!! [5 pts] Write the class SodaMachine that will represent a typical soda vending machine (product name, price). An instance of SodaMachine has
Python Help !!!!!
[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 methodd
>>> 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: $10, but is not the same as Balance= $10
[5 pts] Write the class Line that stores the coordinates of two points in a line and provides the distance between the two points and the slope of the line using the property methods (no attributes) called distance and slope. Unless the slope is equal to infinity, both methods mustreturn the value as float.
Tip: https://www.pdesas.org/ContentWeb/Content/Content/21083/Lesson%20Plan
-
- Coordinates must be provided as tuples when creating your class instances
-
- Use the round method to format your output to 3 decimals [round(ouput_value, 3)].Incorrect format will result in -1 pt from your score
EXAMPLES:
>>> line1=Line((8,3),(0,-4)) #Coordinates provided as tuple>>> line1.distance 10.63 >>> line1.slope
0.875 >>> line2=Line((-7,-9),(1,5.6)) >>> line2.distance 16.648 >>> line2.slope 1.825 >>> line3=Line((2,6),(2,3)) >>> line3.distance 3.0 >>> line3.slope 'Infinity'
-
Quotes mean method returned a string, no need to append them in your code
Deliverables:
Submit your code with the file name LAB5.py to the Lab5 GradeScope assignment before the due date
#Lab #5
#Due Date: 02/08/2019, 11:59PM
########################################
#
# Name:
# Collaboration Statement:
#
########################################
class SodaMachine:
'''
>>> 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 ---
def purchase(self):
#-- start code here ---
def deposit(self, amount):
#-- start code here ---
def restock(self, amount):
#-- start code here ---
class Line:
'''
Creates objects of the class Line, takes 2 tuples. Class must have
2 PROPERTY methods
>>> line1=Line((-7,-9),(1,5.6))
>>> line1.distance
16.648
>>> line1.slope
1.825
>>> line2=Line((2,6),(2,3))
>>> line2.distance
3.0
>>> line2.slope
'Infinity'
'''
def __init__(self, coord1, coord2):
#-- start code here ---
def distance(self):
#-- start code here ---
#-- ends here ---
def slope(self):
#-- start code here ---
#-- ends here ---
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
