CPSC150A
Scientific Computing

Activity 11

Lists

Create List

Write a function create_list(item_1, item_2, item_3, item_4, item_5), which takes 5 parameters of any type. The function should create a list with item_1 as the first element, etc.

Example

Test Code Output
print(create_list(1, 2, 3, 4, 5))) [1, 2, 3, 4, 5]
print(create_list(‘one’, ‘two’, ‘three’, ‘four’, ‘five’)) [‘one’, ‘two’, ‘three’, ‘four’, ‘five’]

Add Ends

Write a function add_ends(a_list), which takes a non-empty list of numbers as a parameter. Your function should return the sum of the first element and the last element from the list.

Example

Test Code Output
print(add_ends([1, 2, 3])) 4
print(add_ends([1])) 2

Birthday Paradox

Suppose a classmate offers to bet you $100 that there are two people in the class that have the same birthday. It seems that the odds would be pretty slim. However, if you are putting $100 on this bet, you might want to figure out your odds of winning.

Details

Create a program that determines the number of people it would take for the probablility of two people in the group to have the same birthday to exceed 50%. The program should print the probability for all groups, from size 2 up to the answer.

The program should not compute the exact probability, instead it should approximate the probability with repeated simulation. That is, repeatedly create a group of birthdays the specified size using a list. The number of times that there are at least identical birthdays divided by the number of times the simulation is repeated is an estimate for the probability. The more times the simulation is repeated, the more accurate it will be, but about 10000 iterations is sufficient.

Example

Group Size: 2 Probability: 0.00282
Group Size: 3 Probability: 0.00836
Group Size: 4 Probability: 0.01613
Group Size: 5 Probability: 0.02668
Group Size: 6 Probability: 0.04042
Group Size: 7 Probability: 0.05691
Group Size: 8 Probability: 0.07511
Group Size: 9 Probability: 0.09479
Group Size: 10 Probability: 0.11764
.
.
.
more lines here

Hint

Submission

Please show your source code and run your programs. Only programs that have perfect functionality will be accepted as complete.