Enter your answers to these questions in the accompanying Python script file questions.py. Questions 1–3 require only short pieces of code to calculate or generate the answers, so replace the entries that say None with your answers to each part. Question 4 has you completing the implementation of two functions.
For questions 1–3, a helper function, fact(n), has been included that provides a simpler interface to SciPy’s factorial function. Note that the comb function will produce real numbers as output instead of integers. The assessment scheme will accept either, as long as the value is correct.
(HINT): While developing your code, store the result in a variable so that Spyder doesn’t immediately try to display it (since it may be large).
(HINT): Use the len() function to check that your result set is the expected size. If your result, stored in set s, is (necessarily) large, then use code like sorted(s)[:20] to look at only the first 20 elements of s. The use of sorted() will often make it easier for you to confirm that it is generating the right entries.
If your script file takes more than ~3 seconds to run then you’ve probably implemented one of the set comprehensions incorrectly.
QUESTIONS (input your answer to these questions to the corresponding parts in the python file provided):
Question 1: Permutations
How many strings of length three are possible using characters from ‘ATGC’ (characters may be reused)? Write Python code tocalculate the number.
Write a set comprehension to generate those strings.
How many four-word sentences can be created from the words ‘cat’, ‘bat’, ‘hat’, ‘sat’, ‘fat’, and ‘rat’, using each word at most once? (Most of the sentences won’t make sense.) Write Python code to calculate the number.
Write a set comprehension to generate tuples (not single strings) of the different arrangements described in part (c).