Finishing 7 new elements

This commit is contained in:
2020-01-09 17:35:57 +01:00
parent 1dcfd757e8
commit f6539aedaa
7 changed files with 404 additions and 0 deletions

66
Dropbox/3-chefs.py Normal file
View File

@@ -0,0 +1,66 @@
class AbstractCook:
def __init__(self):
self.food_name = ""
self.drink_name = ""
self.food = 0
self.drink = 0
def add_food(self, amount, price):
self.food += amount * price
def add_drink(self, amount, price):
self.drink += amount * price
def total(self):
return "{}: {}, {}: {}, Total: {}".format(
self.food_name,
str(self.food),
self.drink_name,
str(self.drink),
str(self.drink + self.food)
)
class JapaneseCook(AbstractCook):
def __init__(self):
super().__init__()
self.food_name = "Sushi"
self.drink_name = "Tea"
class RussianCook(AbstractCook):
def __init__(self):
super().__init__()
self.food_name = "Dumplings"
self.drink_name = "Compote"
class ItalianCook(AbstractCook):
def __init__(self):
super().__init__()
self.food_name = "Pizza"
self.drink_name = "Juice"
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
client_1 = JapaneseCook()
client_1.add_food(2, 30)
client_1.add_food(3, 15)
client_1.add_drink(2, 10)
client_2 = RussianCook()
client_2.add_food(1, 40)
client_2.add_food(2, 25)
client_2.add_drink(5, 20)
client_3 = ItalianCook()
client_3.add_food(2, 20)
client_3.add_food(2, 30)
client_3.add_drink(2, 10)
assert client_1.total() == "Sushi: 105, Tea: 20, Total: 125"
assert client_2.total() == "Dumplings: 90, Compote: 100, Total: 190"
assert client_3.total() == "Pizza: 100, Juice: 20, Total: 120"
print("Coding complete? Let's try tests!")

View File

@@ -0,0 +1,21 @@
def to_camel_case(name):
name = name[0].upper() + name[1:]
while True:
try:
index = name.index("_")
name = name[0:index] + name[index+1].upper() + name[index+2:]
except ValueError:
break
return name
if __name__ == '__main__':
print("Example:")
print(to_camel_case('name'))
# These "asserts" using only for self-checking and not necessary for auto-testing
assert to_camel_case("my_function_name") == "MyFunctionName"
assert to_camel_case("i_phone") == "IPhone"
assert to_camel_case("this_function_is_empty") == "ThisFunctionIsEmpty"
assert to_camel_case("name") == "Name"
print("Coding complete? Click 'Check' to earn cool rewards!")

View File

@@ -0,0 +1,36 @@
from datetime import date, timedelta
def most_frequent_days(a):
week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
days = {"Monday": 0, "Tuesday": 0, "Wednesday": 0, "Thursday": 0, "Friday": 0, "Saturday": 0, "Sunday": 0}
plus_a_day = timedelta(days=1)
first_date = date(a, 1, 1)
last_date = date(a, 12, 31)
while first_date <= last_date:
days[week[first_date.weekday()]] += 1
first_date += plus_a_day
return [day for day, count in days.items() if count == max(days.values())]
if __name__ == '__main__':
print("Example:")
print(most_frequent_days(1084))
# These "asserts" are used for self-checking and not for an auto-testing
assert most_frequent_days(1084) == ['Tuesday', 'Wednesday']
assert most_frequent_days(1167) == ['Sunday']
assert most_frequent_days(1216) == ['Friday', 'Saturday']
assert most_frequent_days(1492) == ['Friday', 'Saturday']
assert most_frequent_days(1770) == ['Monday']
assert most_frequent_days(1785) == ['Saturday']
assert most_frequent_days(212) == ['Wednesday', 'Thursday']
assert most_frequent_days(1) == ['Monday']
assert most_frequent_days(2135) == ['Saturday']
assert most_frequent_days(3043) == ['Sunday']
assert most_frequent_days(2001) == ['Monday']
assert most_frequent_days(3150) == ['Sunday']
assert most_frequent_days(3230) == ['Tuesday']
assert most_frequent_days(328) == ['Monday', 'Sunday']
assert most_frequent_days(2016) == ['Friday', 'Saturday']
print("Coding complete? Click 'Check' to earn cool rewards!")

21
Dropbox/unlucky-days.py Normal file
View File

@@ -0,0 +1,21 @@
from datetime import date
def checkio(year: int) -> int:
count = 0
for month in range(1, 13):
current_date = date(year, month, 13)
if current_date.weekday() == 4:
count += 1
return count
if __name__ == '__main__':
print("Example:")
print(checkio(2015))
# These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(2015) == 3, "First - 2015"
assert checkio(1986) == 1, "Second - 1986"
assert checkio(2689) == 2, "Third"
print("Coding complete? Click 'Check' to earn cool rewards!")