Coursework 3
In this coursework, you are required to write several Python functions, by filling in code into the template below. Submit your Python script. via upload on Blackboard before the deadline on
Friday, 13th December 2024 at 1pm.
I suggest aiming to submit at least one hour earlier, to avoid any last-minute computer problems.
Working independently
As with all assessed work in this unit, you must complete this coursework independently on your own. You must not take code from elsewhere, even if it is referenced. You are however allowed to use the lecture notes and exercise solutions freely, and the lecture notes contain all that is required to solve the problems. You are not allowed to ask others for help, and in particular, you are not allowed to send, give, or receive Python code to/from classmates and others.
See the University Guidelines for Academic Malpractice.
Instructions
1. Copy the code out of the template below and save it as a .py file in Spyder (or another Python editor of your choice).
2. Add your name, university ID number and university email address in the docstring at top of the file, where indicated
3. Write code to replace the pass statements in the functions initial_state,
parse_move, validate_move, apply_move, game_won for questions 1–5. For questions 1–5, do not alter the existing play_game function.
4. For questions 6–8, modify only the parse_move and play_game functions as requested.
5. Do not alter the names or parameters of any functions. Do not create any further
functions with the same names. Ensure that these functions can be called with the
parameters precisely as specified, and that they return (not print) values of the correct data types.
6. Submit your work on Blackboard as a .py Python file. Do not submit a screenshot, PDF, Word document, iPython notebook, or file in any other format.
Aspects of this coursework will be marked automatically and failure to follow the problem description or any of the instructions above will result in loss of marks.
To check that your code is working correctly, you may wish to add some of your own tests in a new function – these will not be marked.
If you wish, you can also add other functions to the code, and call them from the required functions. Make sure all code (other than module import statements) is within a function.
Do not create any further functions with the same name as any of the required functions.
. Do not use the input function anywhere in your code. The only use of input allowed is my existing line of code in the play_game function.
. Make sure your functions return the value they should return, not just print the value
to screen.
As this is part of the course assessment, we will not be able to help you solving these
problems. If you are unsure what any question is asking for, please ask on the Blackboard Discussion Forum.
If you provided a valid email address in the docstring at the beginning of your .py file, you will receive a feedback report with your score for each function.
Template code
The template that you should use for your coursework is below. Two functions are provided:
. display_state is a function that displays the state of the game on the screen, using fancy colours!
. play_game is a pre-written basic framework for the game. You must not modify this function for questions 1–5, but it is modified in questions 6–8.
“””
MATH20621 – Coursework 3
Student name: add your name
Student id: add your id number
Student mail: [email protected]
“””
def display_state(s, *, clear=False):
“””
Display the state s
If ‘clear’ is set to True, erase previous displayed states
“””
def colored(r, g, b, text):
rb,gb,bb=(r+2)/3,(g+2)/3,(b+2)/3
rd,gd,bd=(r)/1.5,(g)/1.5,(b)/1.5
return f”