✨ Continue battle mission
This commit is contained in:
11
Incinerator/binary-count.py
Normal file
11
Incinerator/binary-count.py
Normal file
@@ -0,0 +1,11 @@
|
||||
def checkio(number: int) -> int:
|
||||
return list(str(bin(number))).count('1')
|
||||
|
||||
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
if __name__ == '__main__':
|
||||
assert checkio(4) == 1
|
||||
assert checkio(15) == 4
|
||||
assert checkio(1) == 1
|
||||
assert checkio(1022) == 9
|
||||
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
|
60
Incinerator/dialogues.py
Normal file
60
Incinerator/dialogues.py
Normal file
@@ -0,0 +1,60 @@
|
||||
VOWELS = "aeiou"
|
||||
|
||||
|
||||
class User:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.chat = None
|
||||
|
||||
def connect_on_chat(self, o_chat):
|
||||
self.chat = o_chat
|
||||
|
||||
def send(self, text):
|
||||
self.chat.human_chat += "{} said: {}\n".format(self.name, text)
|
||||
robot_text = text.lower()
|
||||
robot_text = "".join(["0" if x in VOWELS else "1" for x in robot_text])
|
||||
self.chat.robot_chat += "{} said: {}\n".format(self.name, robot_text)
|
||||
|
||||
|
||||
class Human(User):
|
||||
pass
|
||||
|
||||
|
||||
class Robot(User):
|
||||
pass
|
||||
|
||||
|
||||
class Chat:
|
||||
def __init__(self):
|
||||
self.human_chat = ""
|
||||
self.robot_chat = ""
|
||||
|
||||
def connect_human(self, human: Human):
|
||||
human.connect_on_chat(self)
|
||||
|
||||
def show_human_dialogue(self) -> str:
|
||||
return self.human_chat.strip('\n')
|
||||
|
||||
def connect_robot(self, robot: Robot):
|
||||
robot.connect_on_chat(self)
|
||||
|
||||
def show_robot_dialogue(self) -> str:
|
||||
return self.robot_chat.strip('\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
|
||||
chat = Chat()
|
||||
karl = Human("Karl")
|
||||
bot = Robot("R2D2")
|
||||
chat.connect_human(karl)
|
||||
chat.connect_robot(bot)
|
||||
karl.send("Hi! What's new?")
|
||||
bot.send("Hello, human. Could we speak later about it?")
|
||||
assert chat.show_human_dialogue() == """Karl said: Hi! What's new?
|
||||
R2D2 said: Hello, human. Could we speak later about it?"""
|
||||
assert chat.show_robot_dialogue() == """Karl said: 101111011111011
|
||||
R2D2 said: 10110111010111100111101110011101011010011011"""
|
||||
|
||||
print("Coding complete? Let's try tests!")
|
41
Incinerator/morse-decoder.py
Normal file
41
Incinerator/morse-decoder.py
Normal file
@@ -0,0 +1,41 @@
|
||||
MORSE = {'.-': 'a', '-...': 'b', '-.-.': 'c',
|
||||
'-..': 'd', '.': 'e', '..-.': 'f',
|
||||
'--.': 'g', '....': 'h', '..': 'i',
|
||||
'.---': 'j', '-.-': 'k', '.-..': 'l',
|
||||
'--': 'm', '-.': 'n', '---': 'o',
|
||||
'.--.': 'p', '--.-': 'q', '.-.': 'r',
|
||||
'...': 's', '-': 't', '..-': 'u',
|
||||
'...-': 'v', '.--': 'w', '-..-': 'x',
|
||||
'-.--': 'y', '--..': 'z', '-----': '0',
|
||||
'.----': '1', '..---': '2', '...--': '3',
|
||||
'....-': '4', '.....': '5', '-....': '6',
|
||||
'--...': '7', '---..': '8', '----.': '9'
|
||||
}
|
||||
|
||||
|
||||
def morse_decoder(code: str) -> str:
|
||||
sentence = ""
|
||||
while len(code) > 0:
|
||||
if code[0] == " ":
|
||||
sentence += " "
|
||||
code = code[2:]
|
||||
next_space = code.find(" ")
|
||||
if next_space != -1:
|
||||
letter = code[0:next_space]
|
||||
code = code[next_space+1:]
|
||||
sentence += MORSE[letter]
|
||||
else:
|
||||
sentence += MORSE[code]
|
||||
code = ""
|
||||
return sentence[0].upper() + sentence[1:]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Example:")
|
||||
print(morse_decoder('... --- ...'))
|
||||
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert morse_decoder("... --- -- . - . -..- -") == "Some text"
|
||||
assert morse_decoder("..--- ----- .---- ---..") == "2018"
|
||||
assert morse_decoder(".. - .-- .- ... .- --. --- --- -.. -.. .- -.--") == "It was a good day"
|
||||
print("Coding complete? Click 'Check' to earn cool rewards!")
|
Reference in New Issue
Block a user