🎉 Hello world
This commit is contained in:
25
Home/all-the-same.py
Normal file
25
Home/all-the-same.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from typing import List, Any
|
||||
|
||||
|
||||
def all_the_same(elements: List[Any]) -> bool:
|
||||
if len(elements) <= 1:
|
||||
return True
|
||||
try:
|
||||
elements.sort()
|
||||
except TypeError:
|
||||
return False
|
||||
return elements[0] == elements[-1:][0]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Example:")
|
||||
print(all_the_same([1, 1, 1]))
|
||||
|
||||
# These "asserts" are used for self-checking and not for an auto-testing
|
||||
assert all_the_same([1, 1, 1]) == True
|
||||
assert all_the_same([1, 2, 1]) == False
|
||||
assert all_the_same([1, 'a', 1]) == False
|
||||
assert all_the_same(['a', 'a', 'a']) == True
|
||||
assert all_the_same([]) == True
|
||||
assert all_the_same([1]) == True
|
||||
print("Coding complete? Click 'Check' to earn cool rewards!")
|
27
Home/bird-language.py
Normal file
27
Home/bird-language.py
Normal file
@@ -0,0 +1,27 @@
|
||||
VOWELS = "aeiouy"
|
||||
|
||||
|
||||
def translate(phrase):
|
||||
sentence = ""
|
||||
pointer = 0
|
||||
while pointer < len(phrase):
|
||||
char = phrase[pointer]
|
||||
if char not in VOWELS:
|
||||
sentence += char
|
||||
pointer += (1 if char == ' ' else 2)
|
||||
else:
|
||||
sentence += char
|
||||
pointer += 3
|
||||
return sentence
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Example:")
|
||||
print(translate("hieeelalaooo"))
|
||||
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert translate("hieeelalaooo") == "hello", "Hi!"
|
||||
assert translate("hoooowe yyyooouuu duoooiiine") == "how you doin", "Joey?"
|
||||
assert translate("aaa bo cy da eee fe") == "a b c d e f", "Alphabet"
|
||||
assert translate("sooooso aaaaaaaaa") == "sos aaa", "Mayday, mayday"
|
||||
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
|
16
Home/flatten-list.py
Normal file
16
Home/flatten-list.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def flat_list(array):
|
||||
result = []
|
||||
for element in array:
|
||||
if isinstance(element, list):
|
||||
result += flat_list(element)
|
||||
else:
|
||||
result.append(element)
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
assert flat_list([1, 2, 3]) == [1, 2, 3], "First"
|
||||
assert flat_list([1, [2, 2, 2], 4]) == [1, 2, 2, 2, 4], "Second"
|
||||
assert flat_list([[[2]], [4, [5, 6, [6], 6, 6, 6], 7]]) == [2, 4, 5, 6, 6, 6, 6, 6, 7], "Third"
|
||||
assert flat_list([-1, [1, [-2], 1], -1]) == [-1, 1, -2, 1, -1], "Four"
|
||||
print('Done! Check it')
|
29
Home/house-password.py
Normal file
29
Home/house-password.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# migrated from python 2.7
|
||||
def checkio(data):
|
||||
numbers = ["0","1","2","3","4","5","6","7","8","9"]
|
||||
alpha = ["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"]
|
||||
beta = ["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"]
|
||||
if(len(data)<10):
|
||||
return False
|
||||
if(has(data, numbers) == False):
|
||||
return False
|
||||
if(has(data, alpha) == False):
|
||||
return False
|
||||
if(has(data, beta) == False):
|
||||
return False
|
||||
return True
|
||||
|
||||
def has(da, ar):
|
||||
for c in da:
|
||||
if(c in ar):
|
||||
return True
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
assert checkio('A1213pokl')==False, 'First'
|
||||
assert checkio('bAse730onE4')==True, 'Second'
|
||||
assert checkio('asasasasasasasaas')==False, 'Third'
|
||||
assert checkio('QWERTYqwerty')==False, 'Fourth'
|
||||
assert checkio('123456123456')==False, 'Fifth'
|
||||
assert checkio('QwErTy911poqqqq')==True, 'Sixth'
|
||||
print('All ok')
|
28
Home/long-repeat.py
Normal file
28
Home/long-repeat.py
Normal file
@@ -0,0 +1,28 @@
|
||||
def long_repeat(line: str) -> int:
|
||||
longest = 0
|
||||
"""
|
||||
length the longest substring that consists of the same char
|
||||
"""
|
||||
current = None
|
||||
current_counter = 0
|
||||
for char in line:
|
||||
if char != current:
|
||||
if current_counter > longest:
|
||||
longest = current_counter
|
||||
current = char
|
||||
current_counter = 1
|
||||
else:
|
||||
current_counter += 1
|
||||
|
||||
if current_counter > longest:
|
||||
longest = current_counter
|
||||
return longest
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert long_repeat('sdsffffse') == 4, "First"
|
||||
assert long_repeat('ddvvrwwwrggg') == 3, "Second"
|
||||
assert long_repeat('abababaab') == 2, "Third"
|
||||
assert long_repeat('') == 0, "Empty"
|
||||
print('"Run" is good. How is "Check"?')
|
32
Home/most-wanted-letter.py
Normal file
32
Home/most-wanted-letter.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import string
|
||||
|
||||
def checkio(text: str) -> str:
|
||||
letters = {x: 0 for x in list(string.ascii_lowercase)}
|
||||
for letter in text:
|
||||
letter = letter.lower()
|
||||
if letter in letters:
|
||||
letters[letter] = letters[letter] + 1
|
||||
|
||||
retour = None
|
||||
retour_count = 0
|
||||
for letter, count in letters.items():
|
||||
if retour_count < count:
|
||||
retour_count = count
|
||||
retour = letter
|
||||
|
||||
return retour
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Example:")
|
||||
print(checkio("Hello World!"))
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert checkio("Hello World!") == "l", "Hello test"
|
||||
assert checkio("How do you do?") == "o", "O is most wanted"
|
||||
assert checkio("One") == "e", "All letter only once."
|
||||
assert checkio("Oops!") == "o", "Don't forget about lower case."
|
||||
assert checkio("AAaooo!!!!") == "a", "Only letters."
|
||||
assert checkio("abe") == "a", "The First."
|
||||
print("Start the long test")
|
||||
assert checkio("a" * 9000 + "b" * 1000) == "a", "Long."
|
||||
print("The local tests are done.")
|
25
Home/non-unique-elements.py
Normal file
25
Home/non-unique-elements.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Your optional code here
|
||||
# You can import some modules or create additional functions
|
||||
|
||||
|
||||
def checkio(data: list) -> list:
|
||||
doublon = []
|
||||
for number in data:
|
||||
if data.count(number) > 1:
|
||||
doublon.append(number)
|
||||
return doublon
|
||||
|
||||
|
||||
# Some hints
|
||||
# You can use list.count(element) method for counting.
|
||||
# Create new list with non-unique elements
|
||||
# Loop over original list
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert list(checkio([1, 2, 3, 1, 3])) == [1, 3, 1, 3], "1st example"
|
||||
assert list(checkio([1, 2, 3, 4, 5])) == [], "2nd example"
|
||||
assert list(checkio([5, 5, 5, 5, 5])) == [5, 5, 5, 5, 5], "3rd example"
|
||||
assert list(checkio([10, 9, 10, 10, 9, 8])) == [10, 9, 10, 10, 9], "4th example"
|
||||
print("It is all good. Let's check it now")
|
23
Home/time-converter-24h-to-12h.py
Normal file
23
Home/time-converter-24h-to-12h.py
Normal file
@@ -0,0 +1,23 @@
|
||||
def time_converter(time):
|
||||
time_string = int(time.replace(':', ''))
|
||||
time_array = time.split(':')
|
||||
if time_string < 100:
|
||||
return "12:{} a.m.".format(time_array[1])
|
||||
elif time_string < 1200:
|
||||
return "{} a.m.".format(time.lstrip('0'))
|
||||
elif time_string < 1300:
|
||||
return "{} p.m.".format(time.lstrip('0'))
|
||||
else:
|
||||
return "{}:{} p.m.".format(int(time_array[0]) - 12, time_array[1])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Example:")
|
||||
print(time_converter('12:30'))
|
||||
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert time_converter('00:00') == '12:00 a.m.'
|
||||
assert time_converter('12:30') == '12:30 p.m.'
|
||||
assert time_converter('09:00') == '9:00 a.m.'
|
||||
assert time_converter('23:15') == '11:15 p.m.'
|
||||
print("Coding complete? Click 'Check' to earn cool rewards!")
|
70
Home/x-o-referee.py
Normal file
70
Home/x-o-referee.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from typing import List
|
||||
|
||||
|
||||
def checkio(game_result: List[str]) -> str:
|
||||
h = horizontal(game_result)
|
||||
v = vertical(game_result)
|
||||
d = diagonal(game_result)
|
||||
if h != "D":
|
||||
return h
|
||||
if v != "D":
|
||||
return v
|
||||
if d != "D":
|
||||
return d
|
||||
return "D"
|
||||
|
||||
|
||||
def horizontal(game_result: List[str]) -> str:
|
||||
for row in game_result:
|
||||
cells = list(row)
|
||||
cells.sort()
|
||||
if cells[0] == '.':
|
||||
continue
|
||||
if cells[0] == cells[-1:][0]:
|
||||
return cells[0]
|
||||
return "D"
|
||||
|
||||
|
||||
def vertical(game_result: List[str]) -> str:
|
||||
new_game_result = []
|
||||
for i in range(len(game_result)):
|
||||
new_game_result.append(game_result[0][i] + game_result[1][i] + game_result[2][i])
|
||||
return horizontal(new_game_result)
|
||||
|
||||
|
||||
def diagonal(game_result: List[str]) -> str:
|
||||
if game_result[1][1] == '.':
|
||||
return "D"
|
||||
if game_result[0][0] == game_result[1][1] and game_result[1][1] == game_result[2][2]:
|
||||
return game_result[1][1]
|
||||
if game_result[0][2] == game_result[1][1] and game_result[1][1] == game_result[2][0]:
|
||||
return game_result[1][1]
|
||||
return "D"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Example:")
|
||||
print(checkio(["X.O",
|
||||
"XX.",
|
||||
"XOO"]))
|
||||
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert checkio([
|
||||
"X.O",
|
||||
"XX.",
|
||||
"XOO"]) == "X", "Xs wins"
|
||||
assert checkio([
|
||||
"OO.",
|
||||
"XOX",
|
||||
"XOX"]) == "O", "Os wins"
|
||||
assert checkio([
|
||||
"OOX",
|
||||
"XXO",
|
||||
"OXX"]) == "D", "Draw"
|
||||
assert checkio([
|
||||
"O.X",
|
||||
"XX.",
|
||||
"XOO"]) == "X", "Xs wins again"
|
||||
assert checkio([".O.", "XXX", ".O."]) == "X", "Xs wins again"
|
||||
assert checkio(["...", "XXX", "OO."]) == "X", "Xs wins again"
|
||||
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
|
Reference in New Issue
Block a user