These ICS4U Grade 12 Computer Science python coding questions will form a part of your final grade for this course and are to be handed in for grading.
For all of the following questions:
Your grade will be based on your ability to demonstrate the overall expectations from the Ontario Computer Studies Curriculum
A1 – Data Types and Expressions
A3 – Designing Algorithms
A4 – Code Maintenance
File Name: “ICS4UexperimentalProbability.py”
A game is played where a coin is flipped once, and 3 six sided dice are rolled once. You win that game if the coin lands on Heads, the first dice is even, the second dice is odd, and the third dice is between 2 and 4 (inclusive).
Let’s pretend you are not very good at calculating the theoretical probability of winning this game. You are going to use your coding skills to calculate the experimental probability of winning by simulating this game a bunch of times.
Write a program that plays this game a random # of times between 100 and 1000 times (each time you run the program it runs a different number of times) and prints out the experimental probability (as a percentage) of winning. The experimental probability is calculated by the number of times you win / number of times played
File Name: “ICS4UdealNoDeal.py”
A game used to be played on TV, called Deal or No Deal (Look it up on Youtube if you want). In this game there are cases with monetary values inside them. The player opens a case revealing one of the monetary values. That value can no longer be won by the player and then a Banker makes the player a monetary offer to quit the game and take the money offered. If the player doesn’t accept, then he picks another case and the game continues. By continuing to play the player runs the risk of opening high value cases and losing the opportunity to win big money. The banker try’s to make offers to encourage the player to quit before he can possibly win the big money. we are going to make a simple simulation of this game.
Your task is going to be to help the contestant decide if they should take the bankers offer or not. Your decision will be based on the average of the remaining unopened cases and comparing it to the bankers offer.
The input for the simulation is as follows:
The output for the simulation will be the average of the remaining unopened cases and a recommendation to take the deal or not take the deal.
Have your program continue forever until a blank input of cases is entered.
For Example, if the inputs were
File Name: “ICS4UcountingPennies.py”
A circle is drawn on the cartesian grid with its center at the origin. A penny is placed on every integer coordinate that lies within or on the circle. You want to determine how many of these pennies fit in a circle of radius R
For example, If the radius of the circle is 4, then 49 pennies will fit inside it
To solve this problem:
Input for the program will be the radius of the circle, output will be the number of possible pennies.
File Name: “ICS4UrecursiveFunction.py”
Take a look at the following recursive function and try to figure out what its purpose is. You can do this by drawing out the activation diagram for the following examples
def doThis(x):
if x == 0:
return 0
else:
return x % 10 + doThis(x // 10)
Write an iterative version of the algorithm and then compare how many times faster your iterative algorithm is compared to the recursive one.
What you need to hand in:
File Name: “ICS4UmultiplyPositive.py”
Write a recursive function that multiplies two positive integers together.
def multiply(a,b):
#Fill in the code
Return to ICS4U Main Page