diff --git a/chap1/p_07.py b/chap1/p_07.py new file mode 100644 index 0000000..a139201 --- /dev/null +++ b/chap1/p_07.py @@ -0,0 +1,6 @@ +# -*- coding: UTF-8 -*- +def template(x,y,z): + print('{}の時の{}は{}'.format(x,y,z)) + return + +template(12, "気温", 22.4) diff --git a/chap1/p_08.py b/chap1/p_08.py new file mode 100644 index 0000000..2ab00ad --- /dev/null +++ b/chap1/p_08.py @@ -0,0 +1,10 @@ +# -*- coding: UTF-8 -*- + +def ciper(word): + + chars = [chr(219-ord(char)) if char.islower() else char for char in word] + return (''.join(chars)) + +english_message = "This is a message" +cryped_message = ciper(english_message) +print(english_message, cryped_message, ciper(cryped_message), sep=' -> ') diff --git a/chap1/p_09.py b/chap1/p_09.py new file mode 100644 index 0000000..b7ac1e5 --- /dev/null +++ b/chap1/p_09.py @@ -0,0 +1,22 @@ +# -*- coding: UTF-8 -*- +import random + +def typoglycemia(sentence): + words = sentence.split() + return " ".join(map(random_sort_inner, words)) + + +def random_sort_inner(word): + if len(word) <= 4: + return word + char_inner = list(word[1:-1]) + random.shuffle(char_inner) + return word[0] + "".join(char_inner) + word[-1] + + +sentence = """\ +I couldn't believe that I could actually understand \ +what I was reading : the phenomenal power of the human mind .\ +""" + +print(typoglycemia(sentence))