COMP9021 Principles of Programming

Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due

COMP9021 Principles of Programming
Term 2, 2024
Coding Quiz 2
Worth 4 marks and due Week 4 Thursday @ 9pm

Description

You are provided with a stub in which you need to insert your code where indicated without doing any changes to the existing code to complete the task. Although it is not needed for this quiz, you may import any module that is already installed in Ed if you wish.

The current code prompts the user for four (4) positive integers and generates a random list of integers. It also displays the generated list, its reverse, the min value, the max value, the sum of all values of the list, the indexes from the middle and wrapping around.

Your task is to implement three (3) functions to practice the pop(), remove(), and append() list methods.

The provided stub and the outputs of the sample test cases explain the task to be performed.

Some of the code in the stub can be very useful to implement the three functions.

Marking
remove_values_no_greater_than_index()
1.25 marks
cap_sum_to()
1.25 marks
increasing_sequence_from()
1.50 marks
---------------------------------------------------------------------------
--------------
Total
4.00 marks

Due Date and Submission

Quiz 2 is due Week 4 Thursday 20 June 2024 @ 9.00pm (Sydney time).

Note that late submission with 5% penalty per day is allowed up to 3 days from the due date, that is, any late submission after Week 3 Sunday 23 June 2024 @ 9pm will be discarded.2

Make sure not to change the filename quiz_2.py while submitting by clicking on [Mark] button in Ed.

It is your responsibility to check that your submission did go through properly using Submissions link in Ed otherwise your mark will be zero for Quiz 2.

Test Cases

$ python quiz_2.py
Enter four positive integers: 0 10 20 5
Here is the list of generated values:
[6, 6, 0, 4, 8, 7, 6, 4, 7, 5]
Here is a reversed copy of the list:
[5, 7, 4, 6, 7, 8, 4, 0, 6, 6]
The minimal and maximal values are, respectively, 0 and 8.
The sum of all values is: 53
Starting from the middle of the list and wrapping around,
the indexes are:
5, 6, 7, 8, 9, 0, 1, 2, 3, 4
In a copy of the list,
removing again and again the leftmost value
not strictly greater than its latest location (index):
[6, 6, 4, 8, 7, 6, 7]
In a copy of the list,
removing again and again the rightmost largest value
so the resulting list of values has a sum no greater than 20:
[6, 0, 4, 4, 5]
In a copy of the list,
starting from the leftmost occurrence of 5 and wrapping around,
collecting again and again the next larger value:
[5, 6, 8]
The original list has not been modified indeed:
[6, 6, 0, 4, 8, 7, 6, 4, 7, 5]

$ python quiz_2.py

Enter four positive integers: 20 12 17 1
Here is the list of generated values:
[11, 10, 2, 4, 10, 10, 1, 5, 9, 2, 0, 6]
Here is a reversed copy of the list:
[6, 0, 2, 9, 5, 1, 10, 10, 4, 2, 10, 11]
The minimal and maximal values are, respectively, 0 and 11.
The sum of all values is: 70
Starting from the middle of the list and wrapping around,
the indexes are:
6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5
In a copy of the list,
removing again and again the leftmost value
not strictly greater than its latest location (index):
[11, 10, 4, 10, 10, 9]
In a copy of the list,
removing again and again the rightmost largest value
so the resulting list of values has a sum no greater than 17:
[2, 4, 1, 5, 2, 0]
In a copy of the list,
starting from the leftmost occurrence of 1 and wrapping around,
collecting again and again the next larger value:
[1, 5, 9, 11]
The original list has not been modified indeed:
[11, 10, 2, 4, 10, 10, 1, 5, 9, 2, 0, 6]

$python quiz_2.py

Enter four positive integers: 50 15 34 8
Here is the list of generated values:
[7, 13, 4, 5, 10, 14, 3, 11, 7, 12, 5, 1, 8, 5, 3]
Here is a reversed copy of the list:
[3, 5, 8, 1, 5, 12, 7, 11, 3, 14, 10, 5, 4, 13, 7]
The minimal and maximal values are, respectively, 1 and 14.
The sum of all values is: 108
Starting from the middle of the list and wrapping around,
the indexes are:
7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6
In a copy of the list,
removing again and again the leftmost value
not strictly greater than its latest location (index):
[7, 13, 4, 5, 10, 14, 11, 12]
In a copy of the list,
removing again and again the rightmost largest value
so the resulting list of values has a sum no greater than 34:
[7, 4, 5, 3, 5, 1, 5, 3]
In a copy of the list,
starting from the leftmost occurrence of 8 and wrapping around,
collecting again and again the next larger value:
[8, 13, 14]
The original list has not been modified indeed:
[7, 13, 4, 5, 10, 14, 3, 11, 7, 12, 5, 1, 8, 5, 3]
5

$python quiz_2.py

Enter four positive integers: 100 18 110 3
Here is the list of generated values:
[4, 14, 14, 5, 12, 11, 13, 16, 3, 17, 3, 2, 14, 8, 1, 6, 10, 7]
Here is a reversed copy of the list:
[7, 10, 6, 1, 8, 14, 2, 3, 17, 3, 16, 13, 11, 12, 5, 14, 14, 4]
The minimal and maximal values are, respectively, 1 and 17.
The sum of all values is: 160
Starting from the middle of the list and wrapping around,
the indexes are:
9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8
In a copy of the list,
removing again and again the leftmost value
not strictly greater than its latest location (index):
[4, 14, 14, 5, 12, 11, 13, 16, 17, 14]
In a copy of the list,
removing again and again the rightmost largest value
so the resulting list of values has a sum no greater than 110:
[4, 14, 5, 12, 11, 13, 3, 3, 2, 8, 1, 6, 10, 7]
In a copy of the list,
starting from the leftmost occurrence of 3 and wrapping around,
collecting again and again the next larger value:
[3, 17]
The original list has not been modified indeed:
[4, 14, 14, 5, 12, 11, 13, 16, 3, 17, 3, 2, 14, 8, 1, 6, 10, 7]

发表评论

电子邮件地址不会被公开。 必填项已用*标注