✨ Continue Ice Base
This commit is contained in:
parent
04609bedc0
commit
b658dcead9
9
IceBase/funny-adding.py
Normal file
9
IceBase/funny-adding.py
Normal file
@ -0,0 +1,9 @@
|
||||
def checkio(data):
|
||||
a, b = data
|
||||
return a + b
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
assert checkio([5, 5]) == 10, 'First'
|
||||
assert checkio([7, 1]) == 8, 'Second'
|
||||
print('All ok')
|
101
IceBase/microwave-ovens.py
Normal file
101
IceBase/microwave-ovens.py
Normal file
@ -0,0 +1,101 @@
|
||||
class MicrowaveBase:
|
||||
def __init__(self):
|
||||
self.time = "00:00"
|
||||
|
||||
def set_time(self, time: str):
|
||||
self.time = time
|
||||
|
||||
def add_time(self, time: str):
|
||||
minute, second = self.time.split(":")
|
||||
minute = int(minute)
|
||||
second = int(second)
|
||||
number_to_add = int(time[0:-1])
|
||||
unit_to_add = time[-1:]
|
||||
if unit_to_add == "s":
|
||||
second += number_to_add
|
||||
while second >= 60:
|
||||
minute += 1
|
||||
second = second - 60
|
||||
else:
|
||||
minute += number_to_add
|
||||
if minute > 90:
|
||||
self.time = "90:00"
|
||||
else:
|
||||
self.time = "{}:{}".format(str(minute).rjust(2, "0"), str(second).rjust(2, "0"))
|
||||
|
||||
def del_time(self, time: str):
|
||||
minute, second = self.time.split(":")
|
||||
minute = int(minute)
|
||||
second = int(second)
|
||||
number_to_add = int(time[0:-1])
|
||||
unit_to_add = time[-1:]
|
||||
if unit_to_add == "s":
|
||||
second -= number_to_add
|
||||
while second <= 0:
|
||||
minute -= 1
|
||||
second *= -1
|
||||
else:
|
||||
minute -= number_to_add
|
||||
if minute < 0:
|
||||
self.time = "00:00"
|
||||
else:
|
||||
self.time = "{}:{}".format(str(minute).rjust(2, "0"), str(second).rjust(2, "0"))
|
||||
|
||||
|
||||
|
||||
class Microwave1(MicrowaveBase):
|
||||
def show_time(self) -> str:
|
||||
print("_"+self.time[1:])
|
||||
return "_"+self.time[1:]
|
||||
|
||||
|
||||
class Microwave2(MicrowaveBase):
|
||||
def show_time(self):
|
||||
print(self.time[0:-1] + "_")
|
||||
return self.time[0:-1] + "_"
|
||||
|
||||
|
||||
class Microwave3(MicrowaveBase):
|
||||
def show_time(self):
|
||||
print(self.time)
|
||||
return self.time
|
||||
|
||||
|
||||
class RemoteControl:
|
||||
def __init__(self, microwave: MicrowaveBase):
|
||||
self.microwave = microwave
|
||||
|
||||
def set_time(self, time: str):
|
||||
self.microwave.set_time(time)
|
||||
|
||||
def add_time(self, time: str):
|
||||
self.microwave.add_time(time)
|
||||
|
||||
def del_time(self, time: str):
|
||||
self.microwave.del_time(time)
|
||||
|
||||
def show_time(self):
|
||||
return self.microwave.show_time()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
|
||||
microwave_1 = Microwave1()
|
||||
microwave_2 = Microwave2()
|
||||
microwave_3 = Microwave3()
|
||||
|
||||
remote_control_1 = RemoteControl(microwave_1)
|
||||
remote_control_1.set_time("01:00")
|
||||
|
||||
remote_control_2 = RemoteControl(microwave_2)
|
||||
remote_control_2.add_time("90s")
|
||||
|
||||
remote_control_3 = RemoteControl(microwave_3)
|
||||
remote_control_3.del_time("300s")
|
||||
remote_control_3.add_time("100s")
|
||||
|
||||
assert remote_control_1.show_time() == "_1:00"
|
||||
assert remote_control_2.show_time() == "01:3_"
|
||||
assert remote_control_3.show_time() == "01:40"
|
||||
print("Coding complete? Let's try tests!")
|
21
IceBase/pangram.py
Normal file
21
IceBase/pangram.py
Normal file
@ -0,0 +1,21 @@
|
||||
def check_pangram(text):
|
||||
"""
|
||||
is the given text is a pangram.
|
||||
"""
|
||||
alphabet = list(map(chr, range(97, 123)))
|
||||
for letter in text.lower():
|
||||
if len(alphabet) == 0:
|
||||
return True
|
||||
if letter in alphabet:
|
||||
alphabet.remove(letter)
|
||||
if len(alphabet) == 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert check_pangram("The quick brown fox jumps over the lazy dog."), "brown fox"
|
||||
assert not check_pangram("ABCDEF"), "ABC"
|
||||
assert check_pangram("Bored? Craving a pub quiz fix? Why, just come to the Royal Oak!"), "Bored?"
|
||||
print('If it is done - it is Done. Go Check is NOW!')
|
52
IceBase/party-invitations.py
Normal file
52
IceBase/party-invitations.py
Normal file
@ -0,0 +1,52 @@
|
||||
class Friend:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.invite = None
|
||||
|
||||
def set_invite(self, date):
|
||||
self.invite = date
|
||||
|
||||
def show_invite(self):
|
||||
if self.invite is not None:
|
||||
return self.invite
|
||||
return "No party..."
|
||||
|
||||
|
||||
class Party:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.friends = []
|
||||
|
||||
def add_friend(self, friend: Friend):
|
||||
self.friends.append(friend)
|
||||
|
||||
def send_invites(self, date: str):
|
||||
for friend in self.friends:
|
||||
friend.set_invite("{}: {}".format(self.name, date))
|
||||
|
||||
def del_friend(self, friend: Friend):
|
||||
self.friends.remove(friend)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
|
||||
party = Party("Midnight Pub")
|
||||
nick = Friend("Nick")
|
||||
john = Friend("John")
|
||||
lucy = Friend("Lucy")
|
||||
chuck = Friend("Chuck")
|
||||
|
||||
party.add_friend(nick)
|
||||
party.add_friend(john)
|
||||
party.add_friend(lucy)
|
||||
party.send_invites("Friday, 9:00 PM")
|
||||
party.del_friend(nick)
|
||||
party.send_invites("Saturday, 10:00 AM")
|
||||
party.add_friend(chuck)
|
||||
|
||||
assert john.show_invite() == "Midnight Pub: Saturday, 10:00 AM"
|
||||
assert lucy.show_invite() == "Midnight Pub: Saturday, 10:00 AM"
|
||||
assert nick.show_invite() == "Midnight Pub: Friday, 9:00 PM"
|
||||
assert chuck.show_invite() == "No party..."
|
||||
print("Coding complete? Let's try tests!")
|
Loading…
Reference in New Issue
Block a user