ICS4U – Python Programming Evaluation 2

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

A3 – Designing Algorithms

  • Read and write data to external data files
  • Process elements of a 2D list

A4 – Code Maintenance

  • Write appropriate internal documentation explaining main points of the code

Important

Since you will be using File Input and Output in these questions, store the name of your data file in a variable in the very first line at the top of your program.  Then use that variable in your code to open the file.

The reason for this is so that I can easily change the file name with my own test data when grading.  I won’t have to go and change anything in your code other than the first line. 

				
					#Example 

inputPath = "dataFileIN.txt"
outputPath = "dataFileOUT.txt"

#Use that variable in your code
file = open(inputPath,"r")

				
			

ICS4U Python Programming Evaluation Question 1

File Name:  “ICS4UcardDeck.py” 

Decks of cards have suits and card values associated with them

For example, a normal deck of 52 playing cards has:

  • 4 suits (Diamonds, Hearts, Spades, Clubs)
  • Each suit has values (2,3,4,5,6,7,8,9,10,Jack,Queen,King,Ace)
If we were making a computer program, we might represent these cards as follows:
  • 2D – 2 of Diamonds
  • JC – Jack of Clubs

Some games might have a different deck of cards with different suits and different card values. 

We want to write a program that, if it was given a file with a list of the suits and a list of the values, it will

  • read the data into a 2D list
  • have the ability to remove specific cards from that list
Specifics:
  • Your program has to read the data and store it in memory in a 2D list matching the format of the picture
    • The input file will only have two lines. The first line are the suits.  The second line is the values for each suit.  They are separated by commas (no spaces)
  • Once it is stored in the 2D list print a nicely formatted grid to the screen
  • Once the 2D grid is displayed to the screen, have the program ask the user what card they want to remove
    • If the card chosen is in the deck remove it by replacing the card in the list by “—“
    • If the card chosen is not in the deck, display an appropriate message
  • Your program should continue to ask for cards to be removed forever. 

ICS4U Python Programming Evaluation Question 2

File Name:  “ICS4UfindThatMine.py” 

This program is based on the original Windows Game of “Minesweeper”.  The goal of that game was to find out where all the mines were in a large grid.  To help you, the game showed a number in one of the grid spaces that told you how many mines there were in a square adjacent to it.  
 
For example, in the following 4 x 4 mine field, the mines are represented by an * character.
 
ICS4U Mine Field Empty

If we would represent the same mine field with the hints, then we would end up with

Your job is going to be to write a program that generates those hint numbers given any mine field of any size.

The input for your program will be from a file that contains the mine field image.  

  • Mines are represented by “*” characters
  • Empty spaces are represented by “.” characters
  • There is a single space between all entries 
  • Your program needs to be able to handle any size mine field with any number of mines at any location.

The output for your program will be the mine field image with all the empty spaces replaced by their hint values (which are the number of adjacent mines). 

  • Write that data to a file, don’t display it to the screen.

Return to ICS4U Main Page