Question: Write recursive code for the following problem using python 3.2+. Define a function named q1() that accepts one integer (n) as a parameter and uses

Write recursive code for the following problem using python 3.2+.Write recursive code for the following problem using python 3.2+. Define a

Define a function named q1() that accepts one integer (n) as a parameter and uses List comprehension to create and return a List containing a sequence of n randomly selected characters. You may use any variable names you need, but the q1() function should return the List - nothing should be printed. The characters should be either 'A', 'B' or 'C' based on the following parameters: bullet An 'A' is three (3) times more likely to be added to the List than a 'B' bullet A 'B' is twice (2 times) as likely to occur than a 'C' This means that there may not be numerically 3 times more 'A' characters than 'B's, but the algorithm is 3 times more likely to add an 'A' than a 'B' and twice as likely to add a 'B' than a 'C'. Example output of the function q1() at the interactive Python prompt: >>> q1(6) ['B', 'A', 'B', 'A', 'A', 'C'] >>> q1(10) ['B', 'C', 'A', 'A', 'B', 'A', 'A', 'A', 'B', 'A']

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!