1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
garik1379 [7]
4 years ago
5

"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequen

ce. Create a for loop that compares the two strings. For each match, add one point to user_score. Upon a mismatch, end the game. Ex: The following patterns yield a user_score of 4: simonPattern: R, R, G, B, R, Y, Y, B, G, Y userPattern: R, R, G, B, B, R, Y, B, G, Y

Computers and Technology
1 answer:
Karolina [17]4 years ago
6 0

Answer:

user_score = 0  #user score is initialized to 0

simonPattern = 'RRGBRYYBGY'# stores the sequence of characters in simonPattern

userPattern  = input("Enter user pattern: ")  # prompts the user to enter user pattern and stores the pattern in userPattern

for x in range(len(simonPattern)):  #loops through entire length of simonPattern using x as index variable

   if userPattern[x] == simonPattern[x]:  # checks if the element at x-th index of userPattern matches the element at x-th index of simonPattern

       user_score = user_score + 1  # adds 1 to user score if above if condition evaluates to true

   else:  #if a mismatch occurs  

       break  #loop break if mismatch occurs

print("User Score:",user_score) #prints the computed user score

Explanation:

The program first declares a simonPattern string variable and assign it a sequence of characters. You can also prompt to enter the Simon pattern as

simonPattern = input("Enter Simon pattern:")

If you want to hard code the values of both simonPattern and userPattern then change the first two statements after user_score =0 statement as:

simonPattern = 'RRGBRYYBGY'

userPattern  = 'RRGBBRYBGY'

Now I will explain the working of the for loop.

for x in range(len(simonPattern)):

len method is used which returns the length of the string stored in simonPattern. For example if simonPattern = 'RRGBRYYBGY' then len returns 10

range method is used to generate a sequence of numbers for x. This means value of x starts from 0 and it  keeps incrementing to 1 until the length of the simonPattern is reached.

At first iteration:

Let suppose user enters the pattern: RRGBBRYBGY

x starts at index 0. Value of x=0 is less than the length of simonPattern i.e. 10 so the body of loop executes. The body of loop contains the following if statement:

if userPattern[x] == simonPattern[x]:

It matches both the string for the value of x.

if userPattern[0] == simonPattern[0]:

First character (at 0th index) of userPattern is R and in simonPattern is also R so this statement executes:  user_score = user_score + 1  which adds 1 to the user_score. So user_score=1

Next iteration:

x=1

if userPattern[1] == simonPattern[1]:

Second character (at 1st index) of userPattern is R and in simonPattern is also R so this statement executes:  user_score = user_score + 1  which adds 1 to the user_score. So user_score=2

Next iteration:

x=2

if userPattern[2] == simonPattern[2]:

Third character (at 12nd index) of userPattern is G and in simonPattern is also G so this statement executes:  user_score = user_score + 1  which adds 1 to the user_score. So user_score=3

Next iteration:

x=3

if userPattern[3] == simonPattern[3]:

Fourth character (at 3rd index) of userPattern is B and in simonPattern is also B so this statement executes:  user_score = user_score + 1  which adds 1 to the user_score. So user_score=4

Next iteration:

x=4

if userPattern[4] == simonPattern[4]:

Fifth character (at 4th index) of userPattern is B and in simonPattern is R so the if part does not execute and program moves to the else part which has a break statement which means the loop break. The next print(user_score) statement print the value of user_score. As user_score=4 computed in above iterations so output is:

User Score: 4

You might be interested in
Cathy designed a website for a cereal brand. When users view the website, their eyes first fall on the brand name, then they vie
PSYCHO15rus [73]

Answer:

dominance

Explanation:

i just took it and got it right

4 0
3 years ago
An algorithm is defined as a well-ordered collection of unambiguous and effectively computable operations that when executed pro
Elodia [21]

Answer:

to be effectively computable, the person is definite, explicit and 'mechanical'.

8 0
4 years ago
Which of the following occupations uses math concepts to determine if a particular event would occur and the related costs of th
krek1111 [17]

The occupations that utilize math concepts to determine if a particular event would occur and the related costs of the occurrence is Actuary statistician.

This statistician helps in related costs of the occurrence as well as other datas.

<h3>Who is actuary statistician?</h3>

Actuaries are experts that works in insurance industry that wirk on data related to risk as well as statistical probabilities of future occurrences.

Learn more about statistians at;

brainly.com/question/15980493

4 0
3 years ago
1. What is the main factor that affects Earth’s average temperature?
user100 [1]

Answer:

1. The Sun is the primary source of energy that influences any planet's temperature, including Earth. The amount of energy received from the Sun is called insolation; the ratio reflected is called the albedo.

2.There are three major ways in which global warming will make changes to regional climate: melting or forming ice, changing the hydrological cycle (of evaporation and precipitation) and changing currents in the oceans and air flows in the atmosphere

3.The warming of Earth is primarily due to accumulation of heat-trapping greenhouse gases, and more than 90 percent of this trapped heat is absorbed by the oceans. As this heat is absorbed, ocean temperatures rise and water expands. This thermal expansion contributes to an increase in global sea level.

4.The main sources of greenhouse gases due to human activity are: burning fossil fuels leading to higher carbon dioxide concentrations. farming and forestry — including land use change via agriculture and livestock. cement manufacture.

5. - Reduce, Reuse, Recycle

- Use Less Heat and Air Conditioning

-Use Less Hot Water

Explanation:

5 0
4 years ago
Which of the following memories would NOT be an example of long-term memory? a. acknowledging that you just sat down b. remember
Sati [7]

Answer: the following memories would NOT be an example of long-term memory are the letter  a) and c)

<em> -acknowledging that you just sat down </em>

-recollecting what you had for breakfast an hour ago

Explanation:

as the Long-term memory, also called inactive memory or secondary memory, is a type of memory that stores memories for a period of time greater than five o six months

6 0
4 years ago
Other questions:
  • A friend of yours is having trouble getting good Internet service. He says his house is too remote for cable TV—he doesn’t even
    11·1 answer
  • Technician A says that wheel speed sensors are a highly probable cause of illuminated EBC warning lamps. Technician B says that
    10·1 answer
  • Which of these is not the correct method for moving text in a document in Word 2016?
    7·1 answer
  • What will be result of below if statement.
    13·1 answer
  • How do I change my PATH?
    7·2 answers
  • Code Problem 2 in Python 2.
    5·1 answer
  • It means fruit- trees garden.
    8·1 answer
  • Create five circles like the Olympic Rings. fill them with the colors given below
    8·1 answer
  • A homeowner uses a smart assistant to set the house alarm, get packages delivery updates, and set time on the outdoor lights. Wh
    14·1 answer
  • Select the correct answer.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!