0% found this document useful (0 votes)
23 views9 pages

For Bear

The document summarizes the tasks of a summative assessment for term 1 covering Python libraries. It lists 11 tasks related to topics like random number generation, image manipulation, and sound file processing. The tasks include multiple choice questions, code writing, and explanation questions. Performance on the tasks will be scored out of a total of 30 marks over a 40 minute time period.

Uploaded by

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

For Bear

The document summarizes the tasks of a summative assessment for term 1 covering Python libraries. It lists 11 tasks related to topics like random number generation, image manipulation, and sound file processing. The tasks include multiple choice questions, code writing, and explanation questions. Performance on the tasks will be scored out of a total of 30 marks over a 40 minute time period.

Uploaded by

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

Characteristics of tasks of summative assessment for term 1

Unit Learning objectives to be checked Levels of thinking Task Type Time to Score* Score
skills number* of perform for
task* (min)* section
Unit 12.1А: 12.6.1.1 use the functions of the library Applying 1, 2 SAQ 3 4 30
Python libraries. Random to get a pseudo-random number.
12.6.1.3 identify code snippets that use Higher order 3 EAQ 7 3
random sequence generation. thinking skills
12.6.2.1 determine standard colors by RGB Knowledge and 4 SAQ 1 1
code. comprehension
12.6.2.2 use commands of module Image in PIL Applying 5, 6a, 6b, SAQ 4 4
library (load, create, size, save) to manipulate 6c
images.
12.6.2.3 apply graphic primitives to Applying 7, 11 SAQ 12 10
create drawings.
12.6.2.4 create filters for image processing. Higher order 8 SAQ 8 5
thinking skills
12.6.3.1 use commands of the Wave library to Knowledge and 9, 10 EAQ, 5 3
process sound files. Comprehension, SAQ
Applying
Total: 40 30 30
Student’s full name:

Teacher:

Subject: Programming

Grade 12 Group

Term I

SUMMATIVE ASSESSMENT

30 marks

Instructions:

1. There are a total of 40 minutes to answer all the questions. (You are not allowed to talk, copy or
seek help from teachers or other students).

2. If you need more space to answer any question, use the pages provided at the back of this booklet
and mention the question number clearly.

3. For all numerical answers, complete solution must be shown and the answer to be rounded to the
nearest significant figure with SI unit.

For all ‘describe’ or ‘explain’ questions, the answer must be in detail and logic fully explained.

For compare/contrast questions, both items must be explained in detail.

Total:

……./30
Notes: The tasks use Python code.

1. Specify two correct ways to include libraries.

Circle the correct numbers to answer:

a) import * from random


b) def randint import from random
c) from random import *
d) from random import randint
e) use random.randint

[2]

2. Write a function to generate random integers from -10 to 10.

Answer:
Import random
Rand=random.randint(-10,10)
Print(Rand)
[2]

3. Explain the next code snippet

1 from random import shuffle


2 lst = list(range(5, 100, 5))
3 shuffle(lst)
4 print(lst[:-17])
Line 2
Creating a list from 5 to 99 with the numbers that divided to 5
Line 3
Mix all items in the list

Line 4
Output the first two items from this list
[3]

4. Fill the gaps to get “green” color.


color = (0, 255, 0)

[1]

5. Write a command to install the PIL library.


pip install pillow
[1]

6. Ruslan needs to load the graphic file below into the program and save it with a new name
“pyth.jpg”.

python.jpg

(a) Write line of code to connect module Pillow.


from PIL import Image
[1]
(b) Write line of code to upload graphic file.
image.Image.open(“pyth.jpg”) [1]
(c) Write line of code save file with new name.
image=Image.save(“newpyth.jpg”)

[1]

7. Complete program to get graphic file below:

- blue filled bar


- outline of bar is white
- distance from edge 20px

from PIL import Image, ImageDraw


new_image = Image.new("RGB", (400, 400), (0, 0, 0))

draw = ImageDraw.Draw(new_image)

draw.rectangle((20,20,380,380), fill=(0,0,255),outline=(255, 255, 255))

new_image.save('new.png', "PNG")

[5]

8. Complete code snippet. Apply a filter to the picture:

- red equate to 100;

- green divided by two;

- blue increase by 100 and decrease by three times.

pixels = file.load()

x, y = file.size

for i in range(x):

for j in range(y):

r, g, b=pixels[x][y]
r=100
b = (b + 100) // 3
pixels[i, j] = g, b, r

[5]

9. Explain that does mean “frame” in *.wav file.


A frame is a term that is often used to refer to a single sample for each channel in a multi-channel audio file.
[1]

10. Complete code snippet to speed up twice wave file.


source = wave.open("in.wav",

mode="rb") dest = wave.open("out.wav",

mode="wb")

dest.setparams(source.getparams())

frames_count = source.getnframes()

data = struct.unpack("<" + str(frames_count) + "h", source.readframes(frames_count))

newdata=data[::2]

newframes = struct.pack("<" + str(len(newdata)) + "h",

*newdata) dest.writeframes(newframes)

source.close()

dest.close() [2]

11. Complete a program to output the picture below.

Note: you can apply any colors

from PIL import Image, ImageDraw

new_image = Image.new("RGB", (300, 200), (255, 255,

255)) draw = ImageDraw.Draw(new_image)

draw.rectangle((100,70,200,170), fill=(0,0,255), outline=(0,0,0))


draw.ellipse((100,70,200,170), fill=(255,255,255), outline=(255,255,255))
new_image.save('new.png', "PNG")

[5]
Mark scheme

Question Max Additional


Answer
№ mark information

1 A 1
D 1
[Max: 2]

2 randint(-10, 10)
randint 1
range from -10 to 10 1
[Max: 2]

3 Line 2: get a list of integers from 5 to 95 with step 5 1 Accept any


Line 3: shuffle the order of the numbers reasonable
1
answers
Line 4: print the last two numbers 1
[Max: 3]

4 (0, 255, 0) 1
pip install pillow 1
5

6(a) from PIL import Image 1

6(b) file = Image.open("icon.jpeg") 1

6(c) file.save("python.jpeg") 1

7 draw.rectangle 1
((20, 20, 1 1 pixel error
380, 380), 1 allowed

fill=(0, 0, 255), 1
outline=(255, 255, 255)) 1
[Max: 5]

8 for i in range(x): 1 mark for x


for j in range(y): and y.
1
r, g, b = pixels[i, j] 1
r = 100 1
g //= 2 1
b = (b + 100) // 3 1
pixels[i, j] = g, b, r 1
[Max: 5]

9 One amplitude value is called a frame. 1

10 newdata = data[::2] Accept any


data correct
1
answer
[::2] 1
[Max: 2]

11 from PIL import Image, ImageDraw


new_image = Image.new("RGB", (300, 200), (255,
255, 255))
draw = ImageDraw.Draw(new_image)
draw.rectangle 1
((100, 70, 200, 170), fill=(0, 0, 255), 1
outline=(0, 0, 0)) 1
draw.ellipse 1
((100, 70, 200, 170), fill=(255, 255, 255)) 1
new_image.save('new.png', "PNG")
[Max: 5]

TOTAL 30

You might also like