We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 4b38fbb + 4c414cc commit f062067Copy full SHA for f062067
octan/09.py
@@ -0,0 +1,18 @@
1
+# スペースで区切られた単語列に対して,各単語の先頭と末尾の文字は残し,それ以外の文字の順序をランダムに並び替えるプログラムを作成せよ.
2
+# ただし,長さが4以下の単語は並び替えないこととする.
3
+# 適当な英語の文(例えば"I couldn't believe that I could actually understand what I was reading : the phenomenal power of the human mind .")を与え,その実行結果を確認せよ.
4
+import random
5
+
6
+string = "I couldn't believe that I could actually understand what I was"\
7
+ " reading : the phenomenal power of the human mind ."
8
+lis = string.split()
9
+rnd_list = []
10
11
+for word in lis:
12
+ if 4 < len(word):
13
+ word = word[0] + \
14
+ "".join(random.sample(word[1:-1], len(word[1:-1]))) + word[-1]
15
+ rnd_list.append(word)
16
17
+rnd_string = " ".join(rnd_list)
18
+print(rnd_string)
octan/10.py
0 commit comments