I would like to count the number of attempts the user took to guess the correct color sequence. I have been stuck for quite a while as I tried to add a count function but it kept being stuck at 0. I'm new at python so any help is much appreciated (I had to remove some unrelated part of the code because I cant fit it in the box (at compare_list section)
import random
colours = ['PINK', 'BLUE', 'YELLOW', 'RED']
random_colours = []
colours_input = []
#handles the users input and stores in a list (colours_input)
def user_input():
i = 1
while i < 5:
a = input('Please enter your selected colours in sequence, colour ' + str(i) + ': ').upper()
while a not in colours:
print('Please only type the colours in the range (PINK, BLUE, YELLOW, RED) ')
a = input('Please enter a valid colour ' + str(i) + ': ').upper()
colours_input.append(a)
i+=1
print('Your selected colour sequence is: ' + str(colours_input))
#Automatically generate four random colours for the user to guess
def randomize():
for i in range (0,4):
random_colours.append(random.choice(colours))
#To check 2 variables: Correct colour in the correct place and correct colour but in the wrong place
def compare_list():
correct_place = 0
if random_colours[0] == colours_input[0]:
colour_1 = True
correct_place = correct_place + 1
else:
colour_1 = False
if random_colours[1] == colours_input[1]:
colour_2 = True
correct_place = correct_place + 1
else:
colour_2 = False
if random_colours[2] == colours_input[2]:
colour_3 = True
correct_place = correct_place + 1
else:
colour_3 = False
if random_colours[3] == colours_input[3]:
colour_4 = True
correct_place = correct_place + 1
else:
colour_4 = False
print('Correct colour in the correct place: ' + str(correct_place))
while correct_place == 4:
print('Congratulations! You are a master mind')
break
else:
colours_input.clear()
user_input()
compare_list()