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
Write an application that accepts up to 20 Strings, or fewer if the user enters the terminating value ZZZ. Store each String in
notsponge [240]

Answer:

count = 20

i = 0

short_strings = []

long_strings = []

while(i<count):

   s = input("Enter a string: ")

   

   if s == "ZZZ":

       break

   

   if len(s) <= 10:

       short_strings.append(s)

   elif len(s) >= 11:

       long_strings.append(s)

   

   i += 1

choice = input("Enter the type of list to display [short/long] ")

if choice == "short":

   if len(short_strings) == 0:

       print("The list is empty.")

   else:

       print(short_strings)

else:

   if len(long_strings) == 0:

       print("The list is empty.")

   else:

       print(long_strings)

Explanation:

*The code is in Python.

Initialize the count, i, short_strings, and long_strings

Create a while loop that iterates 20 times.

Inside the loop:

Ask the user to enter a string. If the string is "ZZZ", stop the loop. If the length of the string is smaller than or equal to 10, add it to the short_strings. If the length of the string is greater than or equal to 11, add it to the long_strings. Increment the value of i by 1.

When the loop is done:

Ask the user to enter the list type to display.

If the user enters "short", print the short list. Otherwise, print the long_strings. Also, if the length of the  chosen string is equal to 0, print that the list is empty.

3 0
4 years ago
Which of the following describes the phishing method of information security crime?
Marianna [84]
<span>C. pretending to be someone else when asking for information</span>
3 0
3 years ago
Read 2 more answers
Consider the following recursive method. public static string recur(int val) { string dig = "" + (val % 3); if (val / 3 &gt; 0)
Oksana_A [137]

The recursive method recur executes itself from within

When the statement System.out.println(recur(32)); is executed, the string value "2101" is printed

<h3>How to determine the output of the statement?</h3>

The flow of the program is as follows:

  • The method keeps updating the string variable dig with the remainder of the val variable divided by 3
  • When the remainder is less than or equal to 0, the method is exited

So, when 32 is divided by 3.

The remainders are 2, 1, 0 and 1

So, the output of the statement is "2101"

Read about java methods at:

brainly.com/question/19271625

5 0
2 years ago
How secure is a password protected word document?
tensa zangetsu [6.8K]
Secure enough to keep someone out who get on your pc but you should encrypted it so no one o the pc or remotely access it with out a password or with out decrypting it
8 0
4 years ago
jane feels listening to music at night helps her to sleep. should jane listen to music the night before a test ​
Pavel [41]

If it help her sleep than yes! Sleep helps you to stay focused during a test.

7 0
3 years ago
Other questions:
  • While at work, Joe asked Dana to show him how to change the copier paper. Joe kept working as she explained the process, and the
    5·2 answers
  • Anna always has a hard time finding files on her computer because she does not know where she saved them. This also affects her
    12·2 answers
  • Which protocol is the data transmission standard for the Internet, responsible for sending information from one computer to anot
    14·1 answer
  • Extended ACLs can filter traffic based on _____. (Points : 3) protocol type
    8·1 answer
  • A Security Policy is: a. How we implement security b. Corporate direction on behavior c. A statement of consequence for failure
    5·1 answer
  • If I was to sort the months of the year in ASCENDING order alphabetically, which
    11·1 answer
  • Authentication is a mechanism whereby unverified entities or supplicants who seek access to a resource provide a label by which
    12·1 answer
  • Sypherpk is good go sub 2 him
    6·2 answers
  • What two things should you do before starting the design process
    8·1 answer
  • How many pixels are in a picture that is 640 pixels wide and 480 pixels high?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!