Due: November 8, 2021
Points: 100
In the given examples, what you type is in red and the program prints what is in black. Your program output should look exactly like the output in the examples, except that what you type won’t be in red.
Now, breathe deeply and calm down. We will do this in steps!
>>> hasduplicates([1, 2, 3, 4, 5, 5, 2])↵ True >>> hasduplicates([1, 2, 3, 4, 5, 6, 7])↵ False
Hint: To generate a random number between a and b inclusive, put
import randomat the top of the program, and then call the function random.randint(a, b).
For 2 people, the probability of 2 birthdays is 0.00220 For 3 people, the probability of 2 birthdays is 0.00880 For 4 people, the probability of 2 birthdays is 0.01680 For 5 people, the probability of 2 birthdays is 0.02940 For 6 people, the probability of 2 birthdays is 0.03940 For 7 people, the probability of 2 birthdays is 0.05900 For 8 people, the probability of 2 birthdays is 0.06840 For 9 people, the probability of 2 birthdays is 0.09700 For 10 people, the probability of 2 birthdays is 0.12360 and so forth
Also print the number of people needed so that the probability of two of them with a birthday in common is over 0.5 after the list of probabilities, like this:
You need 12 people for two of them to have the same birthday with probability at least 0.50000
Of course, the number 12 is highly improbable!
Hint: Don’t be surprised if your probabilities are slightly different than the ones shown in the sample output. As randomness is involved, it is very unlikely your numbers will match the ones shown here.
Call your program “bday.py”.
Write a program that computes the average, standard deviation, maximum difference between air inspired and expired for each breath, and the minimum difference between air inspired and air expired for each breath. Your output should look like this (but with the correct numbers; the ones here are wrong):
Average volume of air inspired is 120.15 ml with a standard deviation of 328.90 Average volume of air expired is 121.82 ml with a standard deviation of 561.20 The maximum difference between air inspired and expired is 289 The minimum difference between air inspired and expired is 5
Call your program “stats.py”.
For a given number n, let k be the least number of iterations needed to reach the number 1 (excluding the initial value). Then k is called the total stopping time of n.
For example, if n = 29, then the sequence is:
29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1and so the total stopping time of 29 is 18.
Write a program that takes as input a positive integer and prints both the sequence and the total stopping time for that integer. The output should look like:
29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 The total stopping time for 29 is 18
Call your program “collatz.py”.

ECS 235A, Computer and Information Security Version of October 23, 2021 at 11:50PM

You can also obtain a PDF version of this. 