ICS4U – Python Programming Evaluation 4

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 your .py python files

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

A1 – Data Types and Expressions

  • Use Objects to create custom data types when solving problems

A2 – Modular Programming

  • Write programs that are divided among multiple classes

A4 – Code Maintenance

  • Write appropriate internal documentation explaining main points of the code

C1 – Modular Design

  • Design programs using object oriented principles
  • Design programs using the principles of modularity

ICS4U Python Programming Evaluation Question 1

File Name:  “ICS4UquadraticClass.py” 

You are going to be writing a program that helps students with some grade 10 math work.

Consider the following: 

  • A quadratic in standard form is written as y = Ax^2 + Bx + C
  • A quadratic in vertex form is written as y = a(x-h)^2 + k

You want to design a Class in Python to represent Quadratic Objects

Requirements of the Quadratic Class

Constructor:

  • Accepts 3 values as parameters (The values of A, B, C from the standard form of a quadratic)
  • It should set  / calculate the values of the field variables listed below

Fields:

  • A, B, C values from the standard form
  • a,h,k values from the vertex form (You will need to calculate these)

Methods:

  • Display in Standard Form
    • Returns a “nicely” formatted String representing the quadratic in standard form
  • Display in Vertex Form
    • Returns a “nicely” formatted String representing the quadratic in vertex form
  • Direction of Opening
    • Returns a String “Up” or “Down”
  • Vertex Coordinates
    • Returns a list representing the vertex.  The first element of the list is the x value of the vertex, the second element of the list is the y value of the vertex
  • Y intercept
    • Returns the value of the y intercept
  • X intercepts
    • Returns a list representing the x intercepts.  If there are no x intercepts, then return an empty list
  • Adding Quadratics
    • Accepts another Quadratic Object as a parameter and then adds it to the calling quadratic object
    • Returns a new quadratic object representing the sum

Test Program

Create a main method that illustrates the functionality of all the methods inside your Quadratic Class. There is no specific problem to solve using the class.

ICS4U Python Programming Evaluation Question 2

File Name:  “ICS4UfractionQuiz.py” 

You are going to be designing a game to help elementary school students with fraction calculations

You want to design a Class in Python to represent Fraction Objects

Requirements of the Fraction Class

Constructor:

  • Accepts 2 integer values representing the numerator and the denominator of the fraction
  • It should set  / calculate the values of the field variables listed below
  • Code a check to see if a denominator of zero was entered and exit the program gracefully.

Fields:

  • numerator and denominator of an improper fraction

Methods:

  • Reduce
    • Reduces an improper fraction to lowest terms.  It doesn’t return a new fraction object, but modifies the calling object
  • Equals
    • Accepts a 2nd fraction object as a parameter and then compares it to the calling fraction object.  
    • Return True or False
  • Override the __str__ function 
    • Return a string in the form “n/d”
  • Add, subtract, multiply, divide two fractions
    • Accepts a 2nd fraction object as a parameter and then performs the required math operation with the calling fraction
    • Return a new fraction object representing the result of the math operation

Quiz Program

Create a main method that acts as a quiz for students.  

  • Display a question and then ask for the answer
    • The answer is on a single line in the form n/d
  • Indicate if they are correct or not.
    • If they didn’t answer correctly or it wasn’t in lowest terms, then tell them the correct answer in lowest terms
  • There should be a random mixture between addition, subtraction, multiplication, and division in the questions you display
  • The quiz should continue until the user indicates they wish to stop

Notes on Questions and Answers

Questions consist of two improper fractions

  • Don’t allow whole numbers as part of the question or as part of the answer.  
    • Don’t generate a question that has a fraction like 3/1 or 5/5 or an answer like 9/1 or 18/3
  • Limit the numerator and the denominator to be at most 15 in your questions

ICS4U Python Programming Evaluation Question 3

You are going to simulate a simple multi player dice game

  • You must design the solution to this simulation using 2 different types of objects. Create one class to represent a Dice.  Create another class to represent a Player.  You can design the specifics of those classes as you see fit.

Players are randomly assigned a type when they join the game. 

  • There is a 30% chance they are Type 1
  • There is a 60% chance they are a Type 2
  • There is a 10% chance they are Type 3

The game is simple. The player rolls 2 dice.  The sum of the dice is recorded.  Players will win the amount of points showing on their dice roll based on the following rules:

  • Type 1 Players will win points with a sum of the dice showing  6 or 7 or 8 or 9
  • Type 2 Players will win points with a sum of the dice showing 2 or 3 or 4 or 5 or 9 or 10 or 11 or 12
  • Type 3 Players will win points with a sum of the dice showing 2 or 3 or 4 or 5 or 6 or 7 or 8 
If the player doesn’t win, then they lose the amount of points showing on their dice roll
 
A running total is kept of their total points after each round is finished.
 
 

Part 1

File Name:  “ICS4UdiceGameObjects.py” 

Let the user enter how many players will play the game and how many rounds to play.

The simulation should show the following each round for each player

  • Player # (Use 1, 2, 3, 4, 5, 6, etc)
  • Players Type
  • Dice Rolls Made
  • Win or Loss
  • New Running Total of Points 

When the game is over it should output the player(s) with the highest amount of points

 

Part 2

File Name: – Any thing you want, you might need multiple modifications

Does one type of player have a better chance at winning then another type of player? You need to give me numerical evidence generated from your simulation to support your answer. Modify your code and use it to generate data for your conclusions.

You can summarize your conclusions in a report structure / presentation / video.  You decide the best format to communicate your results.

Optional Fun Connection:

  • If you have taken data management, you can model this problem as a Probability Distribution, and should be able to calculate the Expected Value of points won per round for each type of player.