Assignment 2
Type: Group Assignment
Due: by 10:00 PM on Tuesday, April 9, 2019
- Prologue
- Part 1: Word Search Puzzles
- Part 2: Basic Python
- How to Turn in Your Code
- Important Grading Criteria
Prologue
This is a group assignment. Remember that you should always be working with your partner. You may NOT divide up the work and complete the parts independently. All work you submit must be fully authored by both you and your partner. I also suggest that you work on one computer and take turns using the keyboard. Here are some suggested policies:
- Set a timer for 10-15 minutes and switch who is using the keyboard. Even if you’re not comfortable using a keyboard, it is important that you get experience doing so in this course.
- If you are currently the driver (i.e. the one using the keyboard), practice talking out loud what you are thinking as you are typing.
- If you are currently the navigator (i.e. the one not using the keyboard), pay close attention to what the driver is doing, offer feedback, and stay involved throughout that time. Do NOT simply sit idly and let the driver work alone.
- Ask each other questions. If you’re confused about something your partner is doing, let them know and ask them if they could explain or clarify their idea. Talking to each other and checking each other’s work is the best way to pair program!
I recommend that you create a folder named assignment2
in your StuWork
directory. If you have the COURSES
drive mounted already, you can do this by executing the commands.
$ cd /Volumes/COURSES/cs111-03-s19/StuWork/USERNAME
$ mkdir assignment2
$ cd assignment2
Note that USERNAME
should be replaced with your actual Carleton ID.
After executing the third command above, you will be inside the assignment2
directory and ready to work.
Part 1: Word Search Puzzles
Introduction
A word search puzzle is a game that consists of a list of words and a large table of characters, and the objective is to find every given word in the table. The challenge is that the words may appear horizontally, vertically, or diagonally; similarly, they may appear backwards or forwards. Thus, there are eight possible orientations of a word in the table. To make them especially hard to find, any unused space in the table is filled with random characters.
Below is an example of a word search puzzle.
List of Words:
COMPUTER | SCIENCE | TITUS | NATHANIEL |
Table of Letters
E | Z | S | H | O | C | N | T | E | R |
N | L | Y | U | U | R | J | G | N | R |
K | T | E | Z | T | I | S | F | J | E |
D | H | I | I | I | I | R | F | I | T |
H | M | S | Q | N | H | T | X | U | U |
G | U | M | E | Z | A | S | Y | H | P |
U | G | O | F | O | D | H | T | P | M |
X | S | Y | T | L | F | P | T | Q | O |
C | F | Z | L | C | R | J | Y | A | C |
P | S | C | I | E | N | C | E | R | N |
Word Search Algorithm
Your task for this part is to describe an algorithm that, when given an arbitrary word search puzzle, will help me successfully find the locations of all the words. Since you do not know much Python yet, your algorithm will be written in English prose and I will execute your algorithm with pencil and paper. The challenge of the problem is that you must assume that I have very limited memory, but I have access to a lot of paper and a pencil.
You may assume that I can do the following things reliably:
- Understand the English alphabet,
- Draw symbols such as alphabetic characters or place special markings on characters (e.g. circling, drawing a line through, or placing a dot above a character or word),
- Use an eraser extremely precisely (e.g. remove a marking from a character),
- Remember a few words or characters in my head, but not more than three,
- Recognize a word or character I am thinking about, and
- Use my fingers to keep track of where I am on the paper and understand concepts such as left, right, up, down, etc.
You may also assume that I know how to copy the list of words and the entire table of characters onto paper so that I can mark on it in future instructions.
Given your algorithm, I should be able to solve any word search puzzle. After executing your algorithm, I should be holding a piece of paper that includes the original table of characters with each of the hidden words circled. No other markings or symbols should be present on this piece of paper.
You should write your algorithm in a plain text file named word_search.txt
. Instructions for how to submit your files is provided at the end of the assignment.
Part 2: Basic Python
This part is designed to get you started writing simple python programs.
a. Temperature Converter
Write a Python program named convert.py
that converts temperatures from Fahrenheit to Celsius. It should prompt the user for a number, and then print the result. Below is an example run of the program:
$ python3 convert.py
Enter a temperature in Fahrenheit: 70.0
The temperature in Celsius is: 21.11111111111111
b. Quiz Average
As discussed in the Syllabus, I will compute your final quiz grade by dropping your lowest quiz score and taking the average of the rest.
Write a Python program named quiz_average.py
that asks the user to type in four quiz scores and then prints the lowest quiz score and the average of the remaining three as output.
$ python3 quiz_average.py
Enter the first score: 7
Enter the second score: 8
Enter the third score: 5
Enter the fourth score: 9
The lowest score is: 5.0
The average of the remaining scores is: 8.0
c. Voting Age
Write a Python program named voter.py
that asks the user what year they were born and then prints the first U.S. presidential election year that they can vote in. This is a bit trickier since the user needs to be at least 18 to vote and presidential elections only happen on years that are divisible by four. (For simplicity, you may assume that the user of your program was born before November.)
$ python3 voter.py
What year were you born? 2000
The first presidential election year you will be able to vote is: 2020
Here is the challenge: you are not allowed to use conditionals or loops to solve this problem! Below demonstrates a trick that allows you to compute the decade someone was born in. You will need to do something similar in your voter.py
solution.
import math
birth_year = 1996
decade = math.floor(birth_year / 10)
print("You were born in the", decade, "0s.")
# Or with slightly better spacing
print("You were born in the " + str(decade) + "0s.")
How to Turn in Your Code
a. Make sure that you and your partner are clearly identified at the top of every file you have created for this assignment.
b. All of your files need to be placed into the Hand-in/USERNAME/assignment2
directory. You can do this visually in Finder
by copying all of your files in your StuWork/USERNAME/assignment2
directory into your Hand-in/USERNAME/assignment2
directory.
(If you prefer to do this in the Terminal
, I will guide you through it at the end of this page.)
c. Send all of your files to your partner so they have access to them, too!
Copying via the Terminal
I am assuming that you did all of your work in the StuWork/USERNAME/assignment2
directory as described above.
a. Make sure you are in the course directory by executing
$ cd /Volumes/COURSES/cs111-03-s19
b. To copy your StuWork/USERNAME/assignment2
directory into the Hand-in/USERNAME
directory, all you need to do is execute
$ cp -r StuWork/USERNAME/assignment2 Hand-in/USERNAME
The -r
in the copy command stands for “recursive” and makes the command copy all sub-folders and files contained in the folder, too.
Important Grading Criteria
Your assignment will be graded according to the following criteria:
- SUBMISSION. Are the files submitted correctly? Are authors clearly identified at the top of each file?
- PART 1.
- READABILITY. Is the algorithm clear and easy to understand?
- DETAIL. Is the algorithm written with the appropriate level of detail? Are the instructions of appropriate complexity? (e.g. simple enough for the actor to understand what’s being asked)
- COMPONENTS. Does the algorithm make good use of conditionals, repetition, etc., and/or broken down into helpful subroutines?
- PART 2.
- Are the programs named correctly?
- Do they prompt the user with helpful messages?
- Do the programs work correctly?