Question

In: Computer Science

Variable trials refers to a list where each list item is another list of 3 integers...

Variable trials refers to a list where each list item is another list of 3 integers between 0 and 9. Imagine each list of 3 integers is a combination of numbers of a lock. Further suppose the variable code refers to a list of three integers that is the correct combination of the lock.

Write a program which, assuming trials and code are already defined, prints out a character for each digit of each trial. Print Y if the digit in the trail matches the digit at the same position in the code. Print # if the digit in the trial does not match the digit at the same position in the code but appears elsewhere in the code. Print N if the digit of the trial does not match the digit in the code and the digit in the trial appears nowhere in the code. Print a newline after the characters after three numbers (for each trial).

Example, if trails = [[2,3,4], [5,5,5], [5,2,3]], and code = [2,3,5], the program output should be:

Y Y N

# # Y

# # #

Hint: the in and not in operators can be used to test whether an item appears in a list.

(language python.)

Solutions

Expert Solution

Below is a screen shot of the python program to check indentation. Comments are given on every line explaining the code.

Below is the output of the program:


Below is the code to copy:
#CODE STARTS HERE----------------
#Predefined trails and code
trails = [[2,3,4],[5,5,5],[5,2,3]]
code = [2,3,5]

#Loop through the trails
for trail in trails:
   #Loop through each digit in the trail using index
   for x in range(len(trail)):
      # Checks if elements at the same position are matching
      if trail[x] == code[x]:
         print("Y",end=" ")
      #Checks if digit is anywhere in 'code'
      elif trail[x] in code:
         print("#",end=" ")
      #Checks if digit is not in 'code'
      elif trail[x] not in code:
         print("N",end=" ")
   print() #Prints new line after each trail
#CODE ENDS HERE------------------

Related Solutions

#Write a program in Python that given a list of positive integers, return another list where...
#Write a program in Python that given a list of positive integers, return another list where each element corresponds to the sum of the digits of the elements o#f the given list. #Example: # input # alist=[124, 5, 914, 21, 3421] # output # sum=[7, 5, 14, 3, 18]
Can you make links out of lists where each item in a list is its own...
Can you make links out of lists where each item in a list is its own link? How might you accomplish this? expalin how you can do it with a example.
Can you make links out of lists where each item in s list is its own...
Can you make links out of lists where each item in s list is its own link? How might you accomplish this? explain it with a good examplle
Write a program that first gets a list of 5 integers from input. Then, get another...
Write a program that first gets a list of 5 integers from input. Then, get another value from the input, and output all integers less than or equal to that value. Ex: If the input is 50 60 140 200 75 100, the output is: 50 60 75 For coding simplicity, follow every output value by a space, including the last one. Then, output a newline. Such functionality is common on sites like Amazon, where a user can filter results....
give an arbitrary list of integers, how many are 3? (in scheme)
give an arbitrary list of integers, how many are 3? (in scheme)
Imagine you are writing a program to manage a shopping list. Each shopping list item is...
Imagine you are writing a program to manage a shopping list. Each shopping list item is represented by a string stored in a container. Your design requires a print function that prints out the contents of the shopping list. Using a vector to hold the shopping list items, write a print function to print out the contents of a vector of strings. Test your print function with a main program that does the following: Create an empty vector. Append the...
3. For your dependent (Y) variable, you code it 0 for each person where CD4 is...
3. For your dependent (Y) variable, you code it 0 for each person where CD4 is below 200 at the end of study and 1 if CD4 is 200 or above. Then you build a model predicting a function of Y based on age, gender, time since infection, and ARV group in predicting whether or not CD4 count is above or below 200 by the end of the study. a. What is the name for this type of model? Many...
3. Another item in the ACME Jet Propelled Line of products is the ACME Jet Propelled...
3. Another item in the ACME Jet Propelled Line of products is the ACME Jet Propelled Unicycle, which even the most unbalanced individual can ride with ease. The most popular colors for ACME Jet Propelled Unicycles were white, 30%, black, 17%, red, 14%, yellow, 12%, green, 11%, blue 8%, and other, 8%. The following table presents the results of a survey of randomly selected ACME Jet Propelled Unicycle owners in a particular desert area revealed the follwoing. Color White(45) Black(32)...
Please define each of the following terms, direct manufacturing item, indirect manufacturing item, variable manufacturing overhead,...
Please define each of the following terms, direct manufacturing item, indirect manufacturing item, variable manufacturing overhead, fixed manufacturing overhead, pre-determined manufacturing overhead, pre-determined manufacturing overhead rate, and the base for pre-determined manufacturing overhead rate. Then discuss if predetermined manufacturing overhead rate depends on production level. Provide examples to clarify and support your argument. Please provide your answer more than 350 words in word format only. Please dont copy paste from website or from Chegg post. Please give examples for each...
Please define each of the following terms, direct manufacturing item, indirect manufacturing item, variable manufacturing overhead,...
Please define each of the following terms, direct manufacturing item, indirect manufacturing item, variable manufacturing overhead, fixed manufacturing overhead, pre-determined manufacturing overhead, pre-determined manufacturing overhead rate, and the base for pre-determined manufacturing overhead rate. Then discuss if predetermined manufacturing overhead rate depends on production level. Provide examples to clarify and support your argument. Please provide your answer more than 350 words in word format only. Please dont copy paste from website. Please give examples for each definition.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT