Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. The question being asked is the following: to write a function called reverse(D) that takes as input a Python dictionary D (such as the

1. The question being asked is the following: to write a function called reverse(D) that takes as input a Python dictionary D (such as the one above, but it could be a different one) and returns back a new dictionary that provides the inverse definitions (in this example, providing us with a way to convert from real English to Teenager English). Heres an example of reverse in action:

>>> ET = reverse(TE) >>> ET {'hello': 'dude!', 'goodbye': 'ciao or later', 'happy': 'stoked'} >>> ET['goodbye'] 'ciao or later' 

Notice that since both "ciao" and "later" translate to "goodbye" in the input dictionary, the resulting output dictionary has the value 'ciao or later' associated with the 'goodbye' key. In general, the word or is used as the connector between all the words with the same meaning. You may assume that the input dictionary will NOT have "ors" in its values (word definitions).

2. write a function called lengthToATG() that takes no input, generates a random letter from "A", "T", "C", or "G", and then if the last three letters generated are "ATG", it returns the total number of symbols that were generated. Otherwise, it repeats the process by generating a next random letter. Recall that in order to generate things at random, you simply include the line...

import random 

... at the top of your file. Then, you can use random.choice(["A", "T", "C", "G"]) to generate a random symbol from the list ["A", "T", "C", "G"].

Using a while loop, generate symbols until we see the pattern "ATG". Since we don't know in advance how many symbols will need to be generated before we see this pattern, a while loop is the right choice. Then, write a function called meanToATG(trials) that takes a positive integer trials as input and computes the average of the lengthToATG() values over this number of trials.

Now, make a copy of your lengthToATG and meanToATG functions called lengthToAAA and meanToAAA, respectively. These functions will now do the same thing that you just did for "ATG" but for "AAA". Again, use your functions to empirically determine the expected number of symbols until we find the first "AAA" pattern. Write your answer as a comment at the top of your file.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions