Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


COMP0015

Mid-Term Take Home Paper

Sample



Grading:

Grading your solutions will include at least the following criteria:

● Your code will be tested to ensure that it is correct.

● Marks will also be awarded for using good Python style

● Marks will be awarded for using the features of the language properly.

Please see section Computer Science Grading Criteria for more information.


Plagiarism:

Your work will be checked for plagiarism using a world-class plagiarism detection tool, MOSS. MOSS is in the Department of Computer Science and across UCL more widely. According to UCL policy, plagiarism is defined as the presentation of another person’s thoughts or words or artefacts or software as though they were your own. Plagiarism includes copying work from other students, submitting work completed by students in previous years of the course, and copying from journal articles, books and internet sources without correct referencing. Plagiarism seriously undermines the integrity of the College and its graduates and if a deliberate case of plagiarism is suspected in this course it will be treated as cheating under the University of London Proceedings in Respect of Examination Irregularities. Further details of the policy and proceedings can be found on the College website at: https://www.ucl.ac.uk/academic-manual/chapters/chapter-6-student-casework-framework/section-9-student-academic-misconduct-procedure. It is most important that if you feel that you are not able to deal with the study requirements in this course or if you are unsure about referencing conventions, then please ask your lecturer for help. Do not feel tempted to risk your personal reputation and progress through your degree program by plagiarising or cheating.

It is also most important to remember that each assessment task is an opportunity for you to learn and to develop skills that will be of great value in professional and other areas of your life. While you may feel under pressure to complete each assessment task you should not waste important learning opportunities by dishonestly fulfilling the assessment requirements, including copying material directly from the internet. If you are having difficulty meeting assessment deadlines and requirements please contact your Tutor to work out how best to maximise your learning, rather than resorting to plagiarism or cheating.

If you are in any way unsure about the rules and interpretations relating to plagiarism, please contact your personal tutor or the module leader for clarification. Plagiarism will not be tolerated in this module.


Instructions

Complete all questions on this paper.


1) Turtles

In this question you will add code to program circles.py, do not change the name of this file. Your code should be formatted according to the style guidelines at the end of this paper. The program output should look like this:

Notes:

● The distance between the circles in the picture produced will not be measured.

● the turtle draws no visible lines at all, the turtle’s pen colour is white so that its lines are invisible.

● The centre of the orange circle is at position (0, 0). The turtle draws a circle by walking around the outside of the circle. To draw a circle you should move the turtle to the edge of the circle and turn it to face either north or south before drawing the circle.

● Function setup() is used for setting all the characteristics of the turtle before anything else is done. setup() is complete, do not add anything more to it.

You must complete function draw_inside_circle() which draws the orange circle in the middle. The function should use the constants INSIDE_CIRCLE_RADIUS and INSIDE_CIRCLE_COLOR. To fill a shape with color you should use the turtle functions: turtle.fillcolor(), turtle.begin_fill() and turtle.end_fill(). Take a look at the Python documentation for examples.

You must also complete function draw_ring_of_circles(num_circles, outer_circle_radius). This function draws the ring of grey circles.

The parameters are described in the table below:


Submission:

Type your student number into the comment at the top of the file circles.py. Do not change the name of the file. Submit the file circles.py at the submission link on moodle.

[5 marks]


2) Conditions

In this question you will add code to the program midpoint.py, do not change the name of this file. Your code should be formatted according to the style guidelines at the end of this paper. You must not use a python list to solve this problem.

Complete the function called has_midpoint() that accepts three integers as parameters and returns True if one of the integers is the midpoint between the other two integers; that is, if one integer is exactly halfway between them. Your function should return False if no such midpoint relationship exists. The integers could be passed in any order; the midpoint could be the 1st, 2nd, or 3rd parameter. You must check all cases. The midpoint can be calculated by adding the three integers and dividing by 3.


Submission:

Type your student number into the comment at the top of the file midpoint.py. Do not change the name of the file. Submit the file midpoint.py at the submission link on moodle.

[7 marks]


3) Loops

In this question you will add code to the program print_grid.py, do not change the name of this file. Your code should be formatted according to the style guidelines at the end of this paper. You must not use a python list to solve this problem.

Complete the function named print_grid() that accepts two integer parameters rows and cols. The output is a comma-separated grid of numbers where the first parameter (rows) represents the number of rows of the grid and the second parameter (cols) represents the number of columns. The numbers count up from 1 to rows x cols. The output is displayed in column-major order, meaning that the numbers shown increase sequentially down each column and wrap to the top of the next column to the right once the bottom of the current column is reached.

Assume that rows and cols are always greater than 0. Here are some example calls to your function and their expected results:


Submission:

Type your student number into the comment at the top of the file print_grid.py. Do not change the name of the file. Submit the file print_grid.py at the submission link on moodle.

[7 marks]


4) Functions

In this question you will add code to the program quiz.py, do not change the name of this file. Your code should be formatted according to the style guidelines at the end of this paper.

Complete the function named quiz(). Function quiz() has one parameter representing the number of questions in the quiz. The function will present the user with multiplication questions that they will answer. The function will inform the user whether the answer is correct or not. If the answer is wrong, the user should be prompted to retry the question. Here is some sample dialogue:



To solve this problem, you are also required to complete the additional function get_two_numbers(). Function get_two_numbers() will return a tuple containing two 1-digit numbers that will be used as operands for the calculation. You must use the random library to generate the 1-digit numbers.


Submission:

Type your student number into the comment at the top of the file quiz.py. Do not change the name of the file. Submit the file quiz.py at the submission link on moodle.

[7 marks]


5) Strings

In this question you will add code to the program alpha_add.py, do not change the name of this file. Your code should be formatted according to the style guidelines at the end of this paper.

Complete the function named alpha_add(). Given a string parameter s, sum all the digits in s between the parentheses ‘{‘ and ‘}’ and return the sum.

For example: alpha_add(‘ab{*23#o8}x’) returns 13.

If a pair of parentheses does not exist or if there are no numbers between the parentheses, the function must return 0.


Submission:

Type your student number into the comment at the top of the file alpha_add.py. Do not change the name of the file. Submit the file alpha_add.py at the submission link on moodle.

[7 marks]


6) Lists

In this question you will add code to the program is_unique.py, do not change the name of this file. Your code should be formatted according to the style guidelines at the end of this paper. You must not use python sets to solve this problem.

Complete the function is_unique() that takes a list of integers as a parameter and returns a boolean value indicating whether or not the values in the list are unique (True for yes, False for no). The values in the list are considered unique if there is no pair of values that are equal. For example, if a variable called test_list contains the following values:

test_list = [3, 8, 12, 2, 9, 17, 43, -8, 46, 203, 14, 97, 10, 4]

Then the call of is_unique(list) should return True because there are no duplicated values in this list.

If instead the list stored these values:

test_list = [4, 7, 2, 3, 9, 12, -47, -19, 308, 3, 74]

Then the call should return False because the value 3 appears twice in this list. Notice that given this definition, a list of 0 or 1 elements would be considered unique.


Submission:

Type your student number into the comment at the top of the file is_unique.py. Do not change the name of the file. Submit the file is_unique.py at the submission link on moodle.

[7 marks]


[PAPER TOTAL: 40 marks]

END OF PAPER


Style Guide

You must adhere to the style guidelines in this section.


Formatting Style

1. Use Python style conventions for your variable names (snake case: lowercase letters with words separated by underscores (_) to improve readability).

2. Choose good names for your variables. For example, num_bright_spots is more helpful and readable than nbs.

3. Name constants properly using capital letters and put them at the top of your program.

4. Indentation: use a tab width of 4 or 8. Your IDE should do this automatically for you. The best way to make sure your program will be formatted correctly is never to mix spaces and tabs -- use only tabs, or only spaces.

5. Put a blank space before and after every operator. For example, the first line below is good but the second line is not:

    

6. Each line must be less than 80 characters long including tabs and spaces. You should break up long lines using \. You don’t need a continuation character if you are breaking up the parameters of a function.

7. Function names should also be in snake_case: encrypt_message(), print_introduction().

8. Functions should be no longer than about 12 lines in length. Longer functions should be decomposed into 2 or more smaller functions.