Respuesta :
Answer:
for i in range(0,10):
if SimonPattern[i] == UserPattern[i]:
score = score + 1
i = i + 1
else:
break
if i == 9:
score = score + 1
print("Total Score: {}".format(score))
Explanation:
This for loop was made using Python. Full code attached.
- For loop requires a range of numbers to define the end points. For this Simon Says game, we are talking about 10 characters, so that must be the range for the for loop: from 0 to 10.
- Conditional if tests if Simon pattern matches User's one characheter by one and add point for each match.
- Break statement is ready to escape the for loop at first mismatch.
- As we are starting from index 0, if the users matched all the characters correctly, then we need to add 1, otherwise the maximun score would be 9 and it should be 10.
The program illustrates the use of loops.
Loops are used to perform operations that need to be repeated in a certain number of times
In this case, the characters of simon_pattern will be compared to the characters of user_pattern.
The for loop in Python where comments are used to explain each line is as follows
#This statement iterates through the characters of user_pattern and simon_pattern
for i in range(10):
#This compares the corresponding characters
if(user_pattern[i] == simon_pattern[i]):
#If the characters match, user_score is incremented by 1
user_score+=1
#If otherwise,
else:
#The loop is forcefully closed
break;
Read more about loops at:
https://brainly.com/question/22057920