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 of these can be used as a smartphone with the power of a laptop?
sashaice [31]
I would go with A) Tablet because that's basically a bigger phone and mobile cmp combined, its not D) because that's a synonym for a smartphone and not C) because paper and pencil is not like a smartphone, and not B) because that's like reading online books.
4 0
3 years ago
Read 2 more answers
A web application with an SQL server database is found to be compromised by an attacker. On examination, the email IDs of the da
Thepotemich [5.8K]

Answer:

This is what we call SQL Injection.

• SQL Injection is when an attacker compromises your database only if it is vulnerable.

• Vulnerability includes leaving an empty ""(value) or forgetting to close anything that could be attacked.

• Ways to prevent injection is to not use string concatenation.

(<em>ex.</em> "hello" + "world")

*  Use parameterized queries.

*   Immediately get rid of any unused code.

5 0
2 years ago
What does dram stand for?
Sati [7]
Dynamic random-access memory
4 0
3 years ago
Read 2 more answers
You should adopt naming standards that do not convey information to potential system attackers.
Nonamiya [84]
True








------------------------------
5 0
3 years ago
Please help will mark brainiest
frozen [14]
Answer community shares a cloud among organizations with similar computing needs
8 0
4 years ago
Other questions:
  • What are the disadvantages of cloud computing?
    9·1 answer
  • Professional photography is a competitive job field. <br> true <br> false
    12·2 answers
  • It is a field that contains a unique identifier for each record in a primary table
    5·1 answer
  • What is the output of the following code snippet? int s1 = 20; if (s1 &lt;= 20) { System.out.print("1"); } if (s1 &lt;= 40) { Sy
    6·1 answer
  • Why does atmospheric pressure does not effect on planes,jet planes and rocket?​
    9·1 answer
  • Complete the code to convert a float to a string. <br> answer=5.3 <br> strAnswer=__ (answer)
    12·2 answers
  • ফাইল ও ফোল্ডারের মধ্যে পার্থক্য কি এবং ৫ টি ইনপুট ডিভাইসের নাম কি​
    7·2 answers
  • Five varieties of software​
    13·1 answer
  • Why hand tools are important in repairing personal computer?​
    13·2 answers
  • How to get flash to work on chrome?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!