Exam Instructions¶
As stated in the course grading page, one part of the course is programming exam that must be completed in order to get a grade higher than 1. The exam needs to be completed on the computers in the university's Examinarium space.
This page contains everything you need to know about this specific exam in advance. Read these instructions carefully and well in advance before going to take the exam. You should also make yourself familiar with generic Exam system instructions if you haven't taken an e-exam yet.
The exam will be open for a sufficiently long window of time so that everyone can find a suitable time for doing it. This calculation takes into account that only limited number of computers in the space have the necessary tools installed.
What Do I Need to Know for the Exam?¶
For now, the exam only contains a single question. This question is a task where similarly to the exercise task, you need to implement a function detailed in the task description. There are multiple task subjects available, and the Exam will assign a random subject for every student. The difficulty of the questions is roughly simila to third and fourth exercises. For reference, the model answer for most of them is around 10 lines of code.
In almost every task you need to have a strong grasp of control flow structures and data structures. In particular you should review how to handle nested data structures (i.e. data structures that contain other data structures). Handling data structures in loops is also important. Please note that handling of more complex data structures has mostly been done in the project topic related exercises. If you haven't done any of them, make sure you have a solid understanding of the example programs in the material.
You can use the offline version of the material in the exam. It can be downloaded from the exam's attachments during the exam. It includes the four main material pages.
Using the Exam Computers¶
You can write and execute Python code on the computers. Before the exam, make absolutely sure know how to write a program with NotePad++, save it in a folder, and run it with Python in the terminal. The computers have WinPython - a ready-to-use package for Windows that contains everything necessary. Since it's free and easy to install, you can try it on your own computer in advance. The exam computers do not have internet access and you are not allowed to bring phones or other devices to the exam space. Python's offline documentation with contents that match what's on docs.python.org is available on the computers.
The following information is also included in the exam's general instructions in the Exam system:
WinPython is found with file explorer from
C:\WinPython. You can open a terminal for using Python by double-clicking the "WinPython Command Prompt" executable. You can navigate to the Downloads folder in the terminal by typing cd C:\Users\Exam\Downloads.NotePad++ can be found with Windows search by typing notepad to the search bar at the bottom. Remember to save your code to the Downloads folder so that it's in the same place with the test code.
Python documentation can be accessed from the
C:\WinPython\python\Doc\html\ folder and opened by double-clicking index.html, and choosing Firefox when prompted for program to open it with.How to Know Your Answer is Correct?¶
All assignments come with a simple test program that you can use to confirm your answer. In order for the test program to work, your code needs to contain a function with the specified name, and your code file itself must also have the name specified in the assignment and be in the same folder with the test program. When you download the test program from Exam, it goes to the Downloads folder. Therefore it's best to also save your own code in the same folder. The test program can be run from the terminal just like any other Python program.
The test program performs a number of tests (number varies between assignments) and informs you which ones pass. If all tests pass, your program works correctly - assuming it's done properly and doesn't just use a conditional structure to return the "right" answer for given arguments. After submitting, your answer will also be tested with random test values.
Unlike the checkers in Lovelace, the test programs do not provide any extra information. However, you are free to add any prints you want to them. Do be careful to make sure you don't change the tests themselves. If you've made changes to the test program, it's best to re-download the original test program from Exam and run it before submitting your answer.
Can the Exam Be Retaken?¶
As per university regulations for exams, the exam can be attempted three times every year: once in the Autumn, once in the Spring, and once in the Summer. You can only attempt the exam once in each of these windows however. Note: Due to how the system works you will become able to make another exam reservation once your exam has been evaluated. However, you need explicit permission to retake it within the same window. Retakes submitted without permission will not be evaluated.
Exam "Answer Box"¶
The Exam system is not connected with Lovelace. In order to make record keeping easier, we've added a "task" below that you can use to indicate to the staff that you've completed the exam. The task will be evaluated manually by the teacher and marked correct if the exam answer was accepted.
Practice Questions¶
This section contains tasks that were candidates for the exam but were rejected at the end. The assingment text and test program are the versions created for the exam so you can use them for practice.
Chess: Knight's Moves¶
In chess, a knight always moves either 1 vertically and 2 horizontally, or vice versa. Your task here is to make a function that determines where a knight can move from the given position. The board is otherwise empty. Rows and columns on the chess board (8x8) are both represented with numbers 1 to 8.
The function receives the knight's current position with chess notation, e.g.
#python3 (4, 4). The function should return a list of squares the knight can move to. As the knight in this example is in the middle of the board there's nothing to limit its movement and therefore the function should return[(2, 3), (2, 5), (3, 2), (3, 6), (5, 2), (5, 6), (6, 3), (6, 5)]
If the knight is near a border or corner, the number of possible moves should obviously be smaller.
The function's name should be knight_moves. It has one parameter, which is the knight's position.
Name your code knight.py
Name your code knight.py
You can test your program with the provided test program if both are in the same folder:
python knight_test.pyGuessing Game¶
Number guessing game. The computer has chosen a random number between 1 and 100. The player must guess what the number before running out of guesses. For each guess the computer tells whether the guess was too high or too low. Your task is to implement playing this game.
Implement a function that runs the game in a loop until the player runs out of guesses or guesses the number. The number of guesses is given to the function as an argument, and so is the chosen number. On each iteration of the loop, the player is prompted for a number, and informed whether it's too high or low. If the player doesn't know how to input an integer, it still counts as a guess.
One game could go as follows:
Guess the number: 50 Too low Guess the number: 70 Too low Guess the number: 90 Too low Guess the number: 95 Too high Guess the number: 93 Correct! You win
The function returns True if the player wins, otherwise False.
The function's name must be guess. It has two parameters: number of guesses and the chosen number.
Name you code guessing.py
Name you code guessing.py
You can test your program with the provided test program if both are in the same folder:
python guessing_test.pyCompression Algorithm¶
Your task is to implement a very simple compression algorithm that compresses strings where the same characters are clumped together a lot. The algorithm compresses a string into a list with two kinds of items: single character if immediately followed by a different character; or a tuple with a character and the number of subsequent same characters. The last character in the string is always a newline which can be ignored. For example, the string
"aaaaaaaaaaaceeeeeeeeeeeeeeeeeeeeedfghiiiiiiaaaaaa\n" would be compressed into the following list:[('a', 11), 'c', ('e', 21), 'd', 'f', 'g', 'h', ('i', 6), ('a', 6)]
Implement a function that performs this compression. The function must return a list like the one above.
Name the function compress. It has one paramter, the string to compress.
Name your code compression.py
Name your code compression.py
You can test your program with the provided test program if both are in the same folder:
python compression_test.py