U8H5
U8H5
(a) Select the possible range of numbers that Number1 will store. 1/1
(b) Select the possible range of numbers that Number2 will store. 1/1
1. Float
2. Integer
(d) Select the true (T) problems with using this algorithm to determine a dice roll
of a six sided dice.
T Score
0 will be a possible
1/1
number
Every number in
including 0 has an
···/0
equal chance of
being generated
Every number
between 1 and 6 has
···/0
an equal chance of
being generated
2. The information below shows a number of uses of the ROUND() library routine.
For each one state what is returned by the routine or the output of the program.
(a) ROUND(73.28379,2) 1/1
73.28
Feedback
The program will output 0 as a possible number.The chance of the dice landing on a 6 (or
zero) will be half as much as it landing on a 1,2,3,4 or 5.(1) This is because 5.5 to 6.0 will
round to 6, whilst 4.5 to 5.499 will round to 5 (and so on for the other numbers).
ROUND(73.28379,2) - remember the number after the comma is the number of decimal
places in this instance we have ,2 therefore 73.28379 becomes 73.28
3.85
Feedback
ROUND(3.8492,2) - remember the number after the comma is the number of decimal
places in this instance we have ,2 therefore 3.8492 becomes 3.85 as the 3rd decimal point
is 9
(c) 1/1
Number ← 21
OUTPUT ROUND(Number, 0)
21
Feedback
We first declare a whole number 21 and then change its value by adding 0.12345 to it
making Number <-- 21.12345. We then round this down to zero (0) decimal places
returning Number to 21.
(d) 1/1
Number ← 23.3
Number ← Number * 0.1
OUTPUT ROUND(Number, 1)
2.3
Feedback
We first declare a float number 23.3 and then change its value by multiplying by 0.1
making Number <-- 22.33. We then round this down to 1 decimal places returning Number
to 2.3
(e) 1/1
ROUND(321.903, 1)
321.9
Feedback
ROUND(17.298, 2)
17.30
Feedback
(g) 1/1
5.928
Feedback
(g) 1/1
CONSTANT Pi ← 3.141592653
PiShort ← ROUND(Pi, 3)
OUTPUT PiShort
3.142
Feedback
The number is rounded to 3 decimal place 3.142 as the fourth decimal place 5 forces the
previous number to be rounded up
3. The following table shows some further Python library routines in use.
heights = [147,162,166,165]
a = max(heights)
b = statistics.mean(heights)
animals.sort()
print(a)
print(b)
print(animals)
166
Feedback
Using the statistics library we are able to obtain the max, min, mean etc. of a list/array - a =
max(heights) looks the biggest number in the heights list/array, which is 166.
160
Feedback
Using the statistics library we are able to obtain the max, min, mean etc. of a list/array - b =
statistics.mean(heights) looks the average/mean number in the heights list/array. This is
calculated by adding all the values together and dividing by the number of values there is.
This is 160.
Incorrect answers for this question mean you need to review how means are calculated
and double check your calculations.
(iii) What order would animals be in, (tick the number for each animal, which
represents the order it is output):
1 2 3 4 Score
Camel 1/1
Cat 1/1
Giraffe 1/1
Zebra 1/1
4. What would the result be from this program is the user enter 3.145 and 1/1
4.56789?
INPUT FirstNumber
INPUT SecondNumber
Result ← FirstNumber + SecondNumber
ResultShort ← ROUND(Result, 4)
OUTPUT ResultShort
7.7129
Feedback
The animals array / list used the sort function. Which means it gets sorted into
alphabetical order.
Feedback for 4:
YOUR answer must match exactly how the code would look in Python, i.e.
Capital and/or lowercase letters must be used correctly.
RandomNumber = round(random.random() * 9 + 1, 1)
Correct answer
import random
Feedback
import random
This allows the system to generate a random number by using the build in library routine.
6. Look at the code below and use this to answer the questions.
1. import statistics
8. candidates.sort()
9. for i in range(0,len(candidates)):
1 2 3 4 5 6 7 8 9 1
Lowest
result:
57
Highest
result:
94
Total of
all
results:
525
(Mean)
average
result:
75
(b) Line 9 and 10 are using iteration to output each candidate in *1/1
alphabetical order, starting at 0 to the length of the list / array. The print
line ignores the number 0 as it adds 1 to i when it is printed so the data
looks like this:
Candidate 1 : Ali
Candidate 2 : Charles
Candidate 3 : Delores
Candidate 4 : Diya
Candidate 5 : Eric
Candidate 6 : Gabriel
Candidate 7 : Hanna
Which line of code enable the data to be sorted in this way?
1. 1
2. 2
3. 3
4. 4
5. 5
6. 6
7. 7
8. 8
9. 9
10. 10
Feedback
The statistics library allow us to be able to manipulate list/arrays to find max, min, mean,
sum and sorts. The lines 4 - 8 make use of these functions to achieve the outputs
required.
This form was created inside North London Collegiate School Jeju.
Does this form look suspicious? Report
Forms