0% found this document useful (0 votes)
17 views11 pages

U8H5

mm

Uploaded by

egdorjkhand28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views11 pages

U8H5

mm

Uploaded by

egdorjkhand28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

U8H5 Total points 25/26

The respondent's email ([email protected]) was recorded on submission of


this form.

1. An algorithm is given below.

(a) Select the possible range of numbers that Number1 will store. 1/1

1. Any number between 0 and 1

2. Whole number between 0 and 1

(b) Select the possible range of numbers that Number2 will store. 1/1

1. Any number between 1 and 6

2. Any number between 0 and 6

3. Whole number between1 and 6

4. Whole number between 0 and 6


(c) What kind of number is Number3 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

There is not an even


chance of generating 1/1
a6

0 will be a possible
1/1
number

0 will not be output


as a possible ···/0
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

Feedback for 1 (d):

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).

Feedback for 2a:

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

(b) ROUND(3.8492,2) 1/1

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

Number ← Number + 0.12345

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

The number is rounded to 1 decimal place 321.9


(f) 1/1

ROUND(17.298, 2)

17.30

Feedback

The number is rounded to 2 decimal place 17.30

(g) 1/1

DECLARE Distance : REAL


Distance ← 5.9283
OUTPUT ROUND(Distance,3)

5.928

Feedback

The number is rounded to 3 decimal place 5.928

(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.

State the correct three outputs from the program.


import statistics

heights = [147,162,166,165]

a = max(heights)

b = statistics.mean(heights)

animals = ['Zebra', 'Cat', 'Giraffe', 'Camel']

animals.sort()

print(a)

print(b)

print(animals)

(i) a is: 1/1

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.

(ii) b is: 1/1

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

Feedback for 3 (iii):

The animals array / list used the sort function. Which means it gets sorted into
alphabetical order.

Feedback for 4:

The result of adding these 2 numbers is 7.71289, so rounding to 4 d.p is 7.71289


5. What needs adding to the algorithm so it outputs outputs a random 0/1
number between 1.0 and 10.0 given to one decimal place.
RandomNumber ← ROUND((RANDOM()*9 + 1),1)
OUTPUT RandomNumber

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.

Remember the import and library name are lowercase.

Programs to help understa…

6. Look at the code below and use this to answer the questions.
1. import statistics

2. examResults = [63, 92, 84, 57, 72, 94, 63]

3. candidates = ["Diya", "Ali", "Charles", "Eric", "Hanna", "Gabriel", "Delores"]

4. print("Lowest result: ", min(examResults))

5. print("Highest result: ", max(examResults))

6. print("Total of all results: ", sum(examResults))

7. print("(Mean) average result: ", statistics.mean(examResults))

8. candidates.sort()

9. for i in range(0,len(candidates)):

10. ......print("Candidate", i+1, ":", candidates[i])


(a) Which lines of code output the following information: *

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

You might also like