Finishing 11 new elements

This commit is contained in:
2020-01-08 17:32:09 +01:00
parent da0609f315
commit 1dcfd757e8
11 changed files with 411 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import string
def to_encrypt(text, delta):
alphabet = list(string.ascii_lowercase)
new_text = []
for letter in text:
if letter.isalpha():
letter_index = alphabet.index(letter) + delta
if letter_index > len(alphabet):
letter_index = letter_index - len(alphabet)
if letter_index < 0:
letter_index = len(alphabet) + letter_index
new_text.append(alphabet[letter_index])
else:
new_text.append(letter)
return "".join(new_text)
if __name__ == '__main__':
print("Example:")
print(to_encrypt('abc', 10))
# These "asserts" using only for self-checking and not necessary for auto-testing
assert to_encrypt("a b c", 3) == "d e f"
assert to_encrypt("a b c", -3) == "x y z"
assert to_encrypt("simple text", 16) == "iycfbu junj"
assert to_encrypt("important text", 10) == "swzybdkxd dohd"
assert to_encrypt("state secret", -13) == "fgngr frperg"
print("Coding complete? Click 'Check' to earn cool rewards!")

28
Mine/morse-encoder.py Normal file
View File

@@ -0,0 +1,28 @@
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_encoder(text):
return " ".join([MORSE[letter] if letter in MORSE.keys() else " " for letter in text.lower()])
if __name__ == '__main__':
print("Example:")
print(morse_encoder('some text'))
'... --- -- . - . -..- -'
# These "asserts" using only for self-checking and not necessary for auto-testing
assert morse_encoder("some text") == "... --- -- . - . -..- -"
assert morse_encoder("2018") == "..--- ----- .---- ---.."
assert morse_encoder("It was a good day") == ".. - .-- .- ... .- --. --- --- -.. -.. .- -.--"
print("Coding complete? Click 'Check' to earn cool rewards!")

View File

@@ -0,0 +1,28 @@
def checkio(matr):
clone = zip(*matr)
modifiedClone = []
for row in clone:
modifiedClone.append(list(map(mult, row)))
for i, row in enumerate(matr):
for j, cell in enumerate(matr[i]):
if cell != modifiedClone[i][j]:
return False
return True
def mult(e):
return -1 * e
if __name__ == '__main__':
assert checkio([[0, 1, 2],
[-1, 0, 1],
[-2, -1, 0]]) == True, 'First'
assert checkio([[0, 1, 2],
[-1, 1, 1],
[-2, -1, 0]]) == False, 'Second'
assert checkio([[0, 1, 2],
[-1, 0, 1],
[-3, -1, 0]]) == False, 'Third'
print('All ok')