Python代写 | COMP1730/COMP6730 – Programming for Scientists Practice Programming


COMP1730/COMP6730 – Programming for Scientists Practice Programming

Question 1: 3 Marks
Let X = x1, x2, . . . , xn be a sequence of numbers. The average or mean of the sequence is defined as
n .
Question 1: Write a function count_less_than_average(x): that returns the number of elements in x that are
(strictly) less than the average of x.
For example:
• If x = [1, 2, 3, 4, 5], count_less_than_average(x) should return 2, since the average of x is 3 and there
are two elements in x less than 3.
• If x = (1, 2, 3, 4, 100), count_less_than_average(x) should return 4, since the average of x is 22 and
there are four elements in x less than 22.
• If x = [], count_less_than_average(x) should return 0 since the average of an empty sequence is undefined.
A skeleton file called is provided (it will be on the desktop). You should write your solution into this
• You can assume that x is a sequence (e.g. a list, tuple, etc.) of numbers.
• You can not assume that x is non-empty.
• The function must return an integer (type int) between 0 and the length of x.
• The function must not modify the argument sequence.
• You must write your solution in the file called found on the desktop.
• The function that you write must be named count_less_than_average and it must take a single parameter.
• Remember that your solution file must contain only function definitions, comments, and optionally import
statements. If it contains anything else, it is invalid and you will receive zero marks. If you run the testing
program, it will tell you if your file is invalid.
Using the testing program
The testing program for this problem is called It is also found on the desktop. To run the testing
program, you only need to run
The program will test the implementation of the function named count_less_than_average in the file
(in the same directory). You should not make any changes to the testing program.
This question does not have multiple levels.