Hi, main idea was to : - get random characters word - randomly colour letters in my word - from this coloured word print all yellow letters
As it is random i need to be sure that at least one letter is yellow so i put yellow color into final variable. This code works but randomly generates error. And i have no idea how solve this problem. Please help me Traceback (most recent call last): File "proj3", line 23, in <module> w = "".join((colorpass[i.end()]) for i in re.finditer(re.escape(Y), colorpass)) File "proj3", line 23, in <genexpr> w = "".join((colorpass[i.end()]) for i in re.finditer(re.escape(Y), colorpass)) IndexError: string index out of range This is my code: from random import choice from string import ascii_letters, digits import re chars = ascii_letters + digits word = "".join([choice(chars) for i in range(10)]) R = '\033[31m' # red G = '\033[32m' # green B = '\033[34m' # blue P = '\033[35m' # purple Y = '\033[93m' # yellow colors = [R, G, B, P, Y] colorpass = "\033[93m" for char in word: colorpass += char + choice(colors) print(colorpass) w = "".join((colorpass[i.end()]) for i in re.finditer(re.escape(Y), colorpass)) print(w) I am using Python 3.5.2 on Ubuntu 16.04 _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor