Due Date: midnight, Friday, 6 December.
This assignment focuses on design and simulation from Chapter 9.
Submit the following programs via Blackboard:
Write a simulation to answer this question. That is, write a program that will randomly generate 100,000 strings of length 5 and count the number of strings that match "to be". You may assume that your strings are lower case letters and spaces only. That is, when you generate your string, you are choosing from the 27 characters: [' ','a','b','c','d',...'y','z']
Write a function to simulate the voting of the 50 states. Your function should take as input the number of elections to simulate, and then simulate the elections in the 50 states, assuming that each has 50% probability of voting for the winner.
In your main() function in your program, you should call your function 1000 times with the input parameter values: 1, 2, 3, 4, 5, and 10, and print out the number of bellweather states you would expect for each number of elections. That is, your output should look like:
Number of Elections Number of Bellweather states 1 your calculation goes here! 2 your calculation goes here! 3 your calculation goes here! 4 your calculation goes here! 5 your calculation goes here! 9 your calculation goes here! 10 your calculation goes here!
angle = random() * 2 * math.pi
The new x and y positions are then given by these formulas:
The program should take the number of steps as an input. Start your walker at the center of a 100x100 grid and draw a line that traces the walk as it progresses.