I'm learning about recursion in Python, and I wrote a small program that I'd like to improve on for the sake of erudition.
The program repeatedly prints lines of asterisks which change colors. The program runs until I stop it. Right now it works as expected, but just by looking at it I can tell there must be a better way to write this recursively, or perhaps using another method.
Please post some answers that demonstrate how to improve this program. You don't have to make use of the termcolor module if you don't want to.
Below is my code:
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)

random.choice('*******************',)supposed to achieve?