私はPythonで再帰について学習しています。私は、エデュケーションのために改良したい小さなプログラムを書きました。繰り返しプログラムで再帰(または他のもの)を実装する
プログラムは、色を変えるアスタリスクの行を繰り返し印刷します。プログラムは私がそれを止めるまで動く。今は期待どおりに動作しますが、見てみると、これを再帰的に書き込む方が良いか、おそらく別の方法を使用する必要があるかもしれません。
このプログラムを改善する方法を示す回答を投稿してください。あなたがしたくない場合は、termcolor
モジュールを使用する必要はありません。以下は
私のコードです:
import random
from termcolor import colored
s = random.choice('*******************',)
colors = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
text_color = ""
def set_color(colors):
global text_color
text_color = random.choice(colors)
while True:
for a in s:
for b in s:
for c in s:
for d in s:
for e in s:
for f in s:
for g in s:
for h in s:
for i in s:
for j in s:
for k in s:
for l in s:
for m in s:
for n in s:
for o in s:
for p in s:
print(colored(a, text_color)), (colored(b, text_color)), (colored(c, text_color)), (colored(d, text_color)), (colored(e, text_color)), (colored(f, text_color)), (colored(g, text_color)), (colored(h, text_color)), (colored(i, text_color)), (colored(j, text_color)), (colored(k, text_color)), (colored(l, text_color)), (colored(m, text_color)), (colored(n, text_color)), (colored(o, text_color)), (colored(p, text_color)), (colored(a, text_color)), (colored(b, text_color)), (colored(c, text_color)), (colored(d, text_color)), (colored(e, text_color)), (colored(f, text_color)), (colored(g, text_color)), (colored(h, text_color)), (colored(i, text_color)), (colored(j, text_color)), (colored(k, text_color)), (colored(l, text_color)), (colored(m, text_color)), (colored(n, text_color)), (colored(o, text_color)), (colored(p, text_color)); set_color(colors)
真実への階段...これは[codereview.se]に適しています – MYGz
回答箱にあなたの意見をお寄せください! – celestialroad
'random.choice( '*******************'、)'とは何ですか? –