-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update code for class on March 10, 2020
- Loading branch information
1 parent
543fed0
commit 42183b8
Showing
18 changed files
with
251 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from enum import Enum | ||
|
||
|
||
class Weekday(Enum): | ||
MONDAY = 1 | ||
TUESDAY = 2 | ||
WEDNESDAY = 3 | ||
THURSDAY = 4 | ||
FRIDAY = 5 | ||
SATURDAY = 6 | ||
SUNDAY = 7 | ||
|
||
|
||
weekdays = (Weekday.MONDAY, Weekday.TUESDAY, Weekday.WEDNESDAY, Weekday.THURSDAY, Weekday.FRIDAY) | ||
weekends = (Weekday.SATURDAY, Weekday.SUNDAY) | ||
|
||
weekday_wake_up = "7am" | ||
weekend_wake_up = "9am" | ||
|
||
for day in Weekday: | ||
print(f'Today is {day.name.capitalize()}') | ||
wake_time = weekday_wake_up if day in weekdays else weekend_wake_up | ||
print(f'Wake up at {wake_time}\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import abc # Abstract Base Class | ||
from math import pi | ||
|
||
|
||
class Shape(abc.ABC): | ||
@abc.abstractmethod | ||
def area(self): | ||
pass | ||
|
||
@abc.abstractmethod | ||
def circumference(self): | ||
pass | ||
|
||
def __str__(self): | ||
return type(self).__name__ | ||
|
||
|
||
class Circle(Shape): | ||
def __init__(self, r): | ||
self.r = r | ||
|
||
def area(self): | ||
return pi * self.r ** 2 | ||
|
||
def circumference(self): | ||
return 2 * pi * self.r | ||
|
||
|
||
class Rectangle(Shape): | ||
def __init__(self, length, width): | ||
self.l = length | ||
self.w = width | ||
|
||
def area(self): | ||
return self.l * self.w | ||
|
||
def circumference(self): | ||
return 2 * self.l + 2 * self.w | ||
|
||
|
||
class Square(Rectangle): | ||
def __init__(self, length): | ||
super().__init__(length, length) | ||
|
||
|
||
if __name__ == '__main__': | ||
shapes = [Square(10), Circle(20), Rectangle(3.4, 1.5)] | ||
|
||
for shape in shapes: | ||
print(f'{shape} area is {shape.area()}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,38 @@ | ||
from datetime import datetime | ||
def update_sale_price(bike, sale_price): | ||
if bike['sold'] is True: | ||
raise Exception("Action not allowed. Bike has already been sold") | ||
bike['sale_price'] = sale_price | ||
|
||
|
||
def lookup_msrp_value(make, model): | ||
""" | ||
Determine original sale price of a bike when new | ||
""" | ||
return 1000 | ||
|
||
|
||
def set_sale_price(bike): | ||
original_value = lookup_msrp_value(bike['make'], bike['model']) | ||
current_year = datetime.now().year | ||
current_value = original_value * (1 - (current_year - bike['year']) * 0.015) | ||
current_value = current_value * bike['condition'] | ||
bike['sale_price'] = current_value | ||
|
||
|
||
def create_bike(cost, make, model, year, condition): | ||
def create_bike(description, cost, sale_price, condition): | ||
return { | ||
'description': description, | ||
'cost': cost, | ||
'make': make, | ||
'model': model, | ||
'year': year, | ||
'sale_price': sale_price, | ||
'condition': condition, | ||
'sold': False, | ||
} | ||
|
||
|
||
def sell(bike): | ||
def sell(bike, sold_for=None): | ||
if sold_for: | ||
update_sale_price(bike, sold_for) | ||
bike['sold'] = True | ||
profit = bike['sale_price'] - bike['cost'] | ||
return profit | ||
|
||
|
||
bike1 = create_bike(100, 'Univega', 'Alpina', 1999, 0.5) | ||
bike1 = create_bike('Univega Alpina, orange', cost=100, sale_price=500, condition=0.5) | ||
# bike1 = { | ||
# 'cost': 100, | ||
# 'make': 'Univega', | ||
# 'model': 'Alpina', | ||
# 'year': 1999, | ||
# 'condition': 0.5, | ||
# 'description': 'Univega Alpina, orange', | ||
# 'sale_price': 500, | ||
# 'sold': False, | ||
# } | ||
|
||
set_sale_price(bike1) | ||
update_sale_price(bike1, 350) | ||
# bike1['sale_price'] = 350.00 | ||
|
||
sell(bike1) | ||
print(sell(bike1)) | ||
# bike1['sold'] = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
from Examples.example_5_methods import Bike, Condition | ||
|
||
bike = Bike(100, 'Univega', 'Alpina', 1999, Condition.OKAY) | ||
bike = Bike('Univega Alpina, orange', Condition.OKAY, sale_price=500, cost=100) | ||
|
||
bike.update_sale_price() # sale price = $350 | ||
bike.service(spent=30, sale_price=600) # cost=$130, sale_price=$600 | ||
|
||
bike.service(30, Condition.GOOD) # cost = $130 | ||
print(bike.sale_price) # 600 | ||
|
||
print(bike.sale_price) # sale price = $560 | ||
|
||
bike.sell() # profit = $430 | ||
print(bike.sell()) # sold=True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.