ICS4U – Python Programming Evaluation 1

Instructions

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:

  • Use a Python IDE of your choice and create a coded solution to each of the given problems.
  • Hand in commented .py files for your solution.

Your grade will be based on your ability to demonstrate the overall expectations from the Ontario Computer Studies Curriculum

A1 – Data Types and Expressions

  • Apply proper data types and mathematical concepts in an algorithm

A3 – Designing Algorithms

  • Apply a recursive algorithm when solving problems

A4 – Code Maintenance

  • Write appropriate internal documentation explaining main points of the code

ICS4U Python Programming Evaluation Question 1

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 

ICS4U Python Programming Evaluation Question 2

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.

  • To keep things simple, in our version there are 10 possible dollar amounts, each in their own individual case:
  • $100, $500, $1000, $5000, $10000, $25000, $50000, $100000, $500000, $1000000
  • The cases are numbered from 1 to 10 with 1 storing the $100 and 10 storing the $1000000

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.

  • If the offer is higher then that average, the player should take the deal, if the offer is lower then that average, the player should not take the deal.

The input for the simulation is as follows:

  • The case #’s are entered on 1 line from the keyboard each separated by commas (Any number of cases can be chosen to be entered each time the simulation is run)
  • The bankers offer is entered next from the keyboard

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 

  •  1,3,10
  • 75000
Then $100, $1000, $1000000 are not available as prizes anymore
  • This leaves an average of (500 + 5000 + 10000 + 25000 + 50000 + 100000 + 500000) / 7 = 98642.86
  • Since the bankers offer is lower then this average, the player should not take the deal.

ICS4U Python Programming Evaluation Question 3

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

ICS4U-Python-Evaluation-1-Pennies

To solve this problem:

  • Write a function that returns True / False if an (x,y) point lies inside or on a circle (Look up the equation of a circle to help figure that out)
  • Use that function and cycle through all possible (x,y) combinations inside a circle of radius R to find the answer.

Input for the program will be the radius of the circle, output will be the number of possible pennies.

ICS4U Python Programming Evaluation Question 4

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

  • doThis(25)
  • doThis(3741)
				
					
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:

  • The two activation diagrams for the examples
  • An explanation on what the recursive function is supposed to do.
  • A program that compares the execution time for the recursive version to the iterative version

 

ICS4U Python Programming Evaluation Question 5

File Name:  “ICS4UmultiplyPositive.py” 

Write a recursive function that multiplies two positive integers together.

  • Look at the count by 3 example in the lesson
  • When you multiply 2 numbers, you basically just continuously add the same number over and over the correct number of times.
				
					
def multiply(a,b):

    #Fill in the code
				
			

Return to ICS4U Main Page