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
Kisachek [45]
3 years ago
10

"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.
Sample output with inputs: 'RRGBRYYBGY' 'RRGBBRYBGY'
User score: 4
in python please
Computers and Technology
2 answers:
Neporo4naja [7]3 years ago
7 0

Answer:

import random

validletters=["R", "G", "B", "Y"]

input1 = ""

for i in range(1,11):

     input1 = input1 + random.choice(validletters)

input2 = input("Input String 2: ")

if len(input2) != 10:

     print("Invalid Length")

else:

     user_score = 0

     for i in range(0,10):

           if(input1[i] == input2[i]):

                 user_score = user_score + 1

           else:

                 break

     print("String: "+input1)

     print("Guess: "+input2)

     print("User Score: "+str(user_score))

Explanation:

The code assumes that user input will always be R, G, B or Y

The next two lines get two string user inputs

import random

This lists the valid letters

validletters=["R", "G", "B", "Y"]

This initializes an empty string

input1 = ""

The following iteration generates the input string of 10 characters

<em>for i in range(1,11): </em>

<em>      input1 = input1 + random.choice(validletters) </em>

This prompts user for input string

input2 = input("Input String 2: ")

This checks if input string is up to length of 10

if len(input2) != 10:

If yes, it prints invalid length

     print("Invalid Length")

else:

If otherwise, user_score is initialized to 0

     user_score = 0

The following iteration checks for matching characters in both strings

<em>      for i in range(0,10): </em>

<em>            if(input1[i] == input2[i]): </em>

<em>                  user_score = user_score + 1  </em><em>This increments user_score by 1 if there is a match</em>

<em>            else: </em>

<em>                  break  </em><em>This ends the program if there is no match</em>

The next three lines print the strings and the user score

     print("String: "+input1)

     print("Guess: "+input2)

     print("User Score: "+str(user_score))

Aleksandr [31]3 years ago
6 0

import random

letters=["R", "G", "B", "Y"]

i = 0

to_guess = ""

while i < 10:

   to_guess += random.choice(letters)

   i += 1

print("Simon says "+to_guess)

user_score = 0

user = input()

for x in range(0, len(to_guess)):

   try:

       if user[x] == to_guess[x]:

           user_score += 1

       else:

           break

   except IndexError:

       break

print("User score: "+str(user_score))

I hope this helps!

You might be interested in
Which osi layer is responsible for directing data from one lan to another?
likoan [24]
The Network layer (1) directs date from one LAN to another.
5 0
4 years ago
When creating a user generated function, what procedure is followed?
marin [14]

When creating a user-generated function, what procedure is followed d) all of the above.

<h3>What are the three factors of user-described characteristic?</h3>

A user-described characteristic has 3 essential additives which might be characteristic declarations, characteristic definition and characteristic called.

The characteristic prototypes are used to inform the compiler approximately the variety of arguments and approximately the specified datatypes of a characteristic parameter, it additionally tells approximately the go-back kind of the characteristic. By this information, the compiler cross-assessments the characteristic signatures earlier than calling.

Read more about the prototype :

brainly.com/question/7509258

#SPJ1

6 0
2 years ago
jeremy wants to buy a horse. he is looking for a brown tennessee walker that is at least five years old and at least 15 hands ta
timurjin [86]

The numbers of records that will be displayed in response to his query is known to be zero (0).

<h3>What is a query?</h3>

A query is known to be a kind of a question or any form of request that is known to be for information that is often expressed in a formal manner.

Note that a database query is one that can be seen as an action query or a a kind of select query.

A select query is one that can help to get back data from a database. based on the question, Jeremy  is looking for a brown Tennessee walker and this is not among the option presented. Therefore the query will come back as zero.

Hence, The numbers of records that will be displayed in response to his query is known to be zero (0).

Learn more about query from

brainly.com/question/25694408

#SPJ1

7 0
1 year ago
Which of the following describe why a repeat block would be used in a project
iogann1982 [59]

Answer :If a project uses a  Repeat block  the same logic always holds when the commands are executed. Both block stacks perform the same behaviour.

Explanation:

4 0
3 years ago
Read 2 more answers
This is science they just dont have the subject buy anyways 
Anna007 [38]
The environment helps us with many many hings thing. The most obvious plants helps us breath and we help them grow because we have the exact opposite breathing pattern. Animals poop almost anywhere they want and farms use it as fertilizer. I hope this enough to help you. Good luck with your work!!<span />
8 0
3 years ago
Read 2 more answers
Other questions:
  • During an interview, your non-verbal communication (body language, gestures, tone of voice, speed of talking,
    6·1 answer
  • Write a method called evenBeforeOdd that accepts an array of integers and rearranges its elements so that all even values appear
    15·1 answer
  • What is a many-to many types of correspondence?
    5·1 answer
  • Oracion con punto focal​
    6·1 answer
  • Which tasks can be completed using the Chart Tools Design tab? Check all that apply.
    9·1 answer
  • Assume that sentence is a variable of type String that has been assigned a value. Assume furthermore that this value is a String
    10·1 answer
  • Name this<br><br>The feature allows you to add text/picture in the background of the document. ​
    11·1 answer
  • How does using wind energy relate to our world today?
    8·2 answers
  • Ishmael would like to capture a selected potion of his screen and then capture action he performs on that selected portion. What
    5·1 answer
  • The internet is based on which three key technologies?.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!