✨ Add some easy one
This commit is contained in:
19
Elementary/digits-multiplication.py
Normal file
19
Elementary/digits-multiplication.py
Normal file
@@ -0,0 +1,19 @@
|
||||
def checkio(number: int) -> int:
|
||||
number = str(number)
|
||||
x = 1
|
||||
for y in number:
|
||||
if y != '0':
|
||||
x *= int(y)
|
||||
return x
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Example:')
|
||||
print(checkio(123405))
|
||||
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert checkio(123405) == 120
|
||||
assert checkio(999) == 729
|
||||
assert checkio(1000) == 1
|
||||
assert checkio(1111) == 1
|
||||
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
|
16
Elementary/easy-unpack.py
Normal file
16
Elementary/easy-unpack.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def easy_unpack(elements: tuple) -> tuple:
|
||||
"""
|
||||
returns a tuple with 3 elements - first, third and second to the last
|
||||
"""
|
||||
return elements[0], elements[2], elements[-2]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Examples:')
|
||||
print(easy_unpack((1, 2, 3, 4, 5, 6, 7, 9)))
|
||||
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert easy_unpack((1, 2, 3, 4, 5, 6, 7, 9)) == (1, 3, 7)
|
||||
assert easy_unpack((1, 1, 1, 1)) == (1, 1, 1)
|
||||
assert easy_unpack((6, 3, 7)) == (6, 7, 3)
|
||||
print('Done! Go Check!')
|
18
Elementary/index-power.py
Normal file
18
Elementary/index-power.py
Normal file
@@ -0,0 +1,18 @@
|
||||
def index_power(array: list, n: int) -> int:
|
||||
"""
|
||||
Find Nth power of the element with index N.
|
||||
"""
|
||||
return (array[n] ** n) if n < len(array) else -1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Example:')
|
||||
print(index_power([1, 2, 3, 4], 2))
|
||||
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert index_power([1, 2, 3, 4], 2) == 9, "Square"
|
||||
assert index_power([1, 3, 10, 100], 3) == 1000000, "Cube"
|
||||
assert index_power([0, 1], 0) == 1, "Zero power"
|
||||
assert index_power([1, 2], 3) == -1, "IndexError"
|
||||
assert index_power([1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 9) == 1, "IndexError"
|
||||
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
|
12
Elementary/multiply-intro.py
Normal file
12
Elementary/multiply-intro.py
Normal file
@@ -0,0 +1,12 @@
|
||||
def mult_two(a, b):
|
||||
return a * b
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Example:")
|
||||
print(mult_two(3, 2))
|
||||
|
||||
# These "asserts" are used for self-checking and not for an auto-testing
|
||||
assert mult_two(3, 2) == 6
|
||||
assert mult_two(1, 0) == 0
|
||||
print("Coding complete? Click 'Check' to earn cool rewards!")
|
Reference in New Issue
Block a user