Due: Wednesday, November 28, 2012 at 5:00PM
Points: 100
Please turn in your answers for the homework assignment on SmartSite, under Homework #3 in Assignments. Turn in your programs answers for the extra credit under Extra Credit #3 there.
Here is sample output:
The string? heLlo↵ heLlo is not abcdearian The string? aLmost↵ aLmost is abcdearian The string? w3i$l0l!ow↵ w3i$l0l!ow is not abcdearian The string? e3f$f0o!rt↵ e3f$f0o!rt is abcdearian The string? cOmpuTer↵ cOmpuTer is not abcdearian The string? ABcDE↵ ABcDE is abcdearian The string? control-D
Please call your program “abcde.py”.
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.12360How many people are needed so that the probability of two of them with a birthday in common is over 0.9? How many are needed such that the probability of two of them having the same birthday is at least 0.5? Put these answers into a comment at the head of the file.
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.
Remember to hand this in under Extra Credit #4, not under Homework #4!
ECS 10, Basic Concepts of Computing Fall Quarter 2012 |