ICT G6 Sem2 Finals Revision

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

SEMESTER 2 REVISION

ACADEMIC YEAR 2023 - 2024


Subject: ICT - Grade: 6

Name: ………………………………………………… Class: ……………

PART A: CONTENT
Topic 1: Introduction to Python Programming
Topic 2: Turtle Graphics
Topic 3: Python Lists
Topic 4: User defined functions
Topic 5: Array with NumPy
Topic 6: Data Visualization using Matplotlib

Introduction to Python Programming


❖ Computers can only understand the instructions in the form of 0s and 1s.
❖ A set of instructions is called a program.
❖ A program written in any programming language is called the source
code.
❖ Language Preprocessors translate the source code into machine code.
❖ Assembler converts assembly language which is also known as low-level
language (LLL) program to machine code.
❖ Interpreter Converts high-level language (HLL) source code to machine
code line by line.
❖ Compiler Converts high-level language (HLL) source code to machine
code in a single go.
❖ Python was developed by Guido Van Rossum in 1991 in the Netherlands.
Python Tokens
 Keywords

Page 1 / 21
The words that have special meaning to the Python Interpreter. Eg: if ,
while, for
 Variables
Variables are used to store values in a computer's memory. Identifier
(variable name) should not contain any special characters except _ or
space. They cannot start with a number.
 Operators
They are symbols that allow certain operations to be performed.
o Arithmetic operators [ +,-,*,**,/,//,% ]
o Logical [or, and, not ]
o Relational [< , <= , > , >=, ==, !=]
 Literals – They are constants of different data types. Basic data types
used are:
o int - Eg: 2023 , 12, 01
o float -Eg: 23.4 , 21.7 , 10.0
o bool – Eg: True, False
o string – Eg: “Python”, “NGS”

 Punctuators – Otherwise known as separators. Eg: ,[ ] { } ( ) : ;

Turtle Graphics
❖ We have to import turtle module before we create graphics with it.
❖ There are multiple methods of importing a turtle module.
import turtle , from turtle import * are two such methods
❖ penup() - Remove pen from making any marks
❖ pendown() - Open pen to start making marks
❖ forward(n) - Move forward n steps
❖ backward(n) - Move backward n steps
❖ right(t) - Turn t angle to right side
❖ left(t) - Turn t angle to left side
❖ pensize(n) - Set the thickness of the pen to n
❖ pencolor() - Set the color of the pen

Page 2 / 21
❖ fillcolor() - Fill color in a closed shape
begin_fill() - Starting point to color
end_fill() - Ending point to color the shape
Python Lists
❖ List is a data structure that can store multiple values in one variable
❖ It can store values of different data types
❖ Values are stored in [ ] with each value separated by commas.
❖ Eg: colors=[‘#cdb4db’, ’#dda15e’, ‘#bde0fe’ , ‘#f28482’ ]
❖ append() - Add new elements to the existing list
❖ sort () - Arrange data in ascending order
❖ max() - Gives the highest value in the list
❖ min() - Gives the smallest element in the list
❖ index() - Gives the index position of the given element

Python User defined functions


❖ When we want one more statement to be saved for later use.
❖ The keyword ‘def ‘ helps to define a user defined function
❖ It has two parts: Function definition statement and function call statement.
❖ The function can take 0 or more arguments as parameters
❖ The function can return 0 or more arguments from it.
Array with NumPy
❖ NumPy is a Python library used for working with arrays.
❖ It stands for numerical Python.
❖ Import statement: import numpy as np
❖ NumPy arrays are stored at one continuous place in memory unlike lists.
❖ Hence makes it faster to access than lists.
❖ np.arange(a,b , i)
arange functions allows us to create a range of numbers from ‘a’ until ‘b’ in
‘I’ intervals.
❖ np.reshape(rows, columns)
rearranges the numbers in the list to the mentioned rows and columns.
❖ np.linspace (a,b,n)
creates a list of linearly spaced ‘n’ vectors ( numbers) between a and b

Data Visualization using Matplotlib

Page 3 / 21
❖ Matplotlib is a low level graph plotting library in python for visualization.
❖ Matplotlib is open source and we can use it freely.
❖ Import the library using the command: import matplotlib.pyplot as plt
❖ Bar graphs to show numbers that are independent of each other.
❖ Pie charts to show you how a whole is divided into different parts.
❖ Line graphs show you how numbers have changed over time.
❖ Chart components:
➢ Type: Choose the type based on the purpose.
➢ Title: Give a heading to the chart to show what the chart is
representing.
➢ Labels: Label the Category (X-axis) and Value (Y-axis).
➢ Legend: Mark each graph line if you are plotting multiple categories.
➢ Color : To distinguish each component.
❖ To plot the graph:
plt.plot ( x, y, label , color, linestyle, marker )
plt.bar( x, height, width, color )
❖ Line styles:
Character Description
- Solid line style
-- Dashed line style
-. Dash- dot line style
: Dotted line style

❖ Markers
Character Description
. Point marker
, Pixel marker
o Circle marker
< or > Triangle marker

PART B: QUESTIONS
1) Fill in the blanks
a) Computers can only understand the instructions in the form of
_code_____ and _data______.

Page 4 / 21
b) Python language is developed by ____Guido van Rossum
____________________.
c) _____Variables___________ are used to store values in a computer’s
memory.
d) ______Compiler__________ is the preprocessor that converts HLL to
machine code line by line.
e) __Turtle_____________ package gives a movable pen to draw
pictures.
f) The single-line comments are written in Python using the symbol
__#__.
g) The angle of turn for a shape with n sides is
_360/n________________.
h) ______Penup______ commands help us to move the turtle without
making a mark on the screen.
i) _____def________ is the keyword to create user defined function.
j) _____reshape________ arranges the series of numbers into rows and
columns
k) ___linspace__________ generates n linearly spaced vectors between
two numbers.
l) __matplotlib____________ library is needed to draw a graph in
Python
m) ___numpy___________ library is needed to create linear spaced
vectors in Python.
n) _turtle__________ is the library needed to draw turtle graphics in
Python.
o) _Arguments____________ are the variables passed in a function call
statement.

Page 5 / 21
Page 6 / 21
2) Complete the Python expression

a) 24 __-___ 3 =8
b) 5553 __//__ 10 = 555
c) 2 ___**__ 10 = 1024
d) 1024 % 10 = __4____
e) 942 % 5 =___2____
f) 3 __**__ 3 = 27
g) ‘5’ + ‘3’ = ___53____
h) 281 // 10 = ___28____
i) 281 / 10 = __28.1_____
j) 281 % 10 = __1_____
3) Identify the type of charts used.
a) To show the sales of each flavor of ice cream in a month -Bar chart

or Pie chart

b) To show how much vanilla ice cream is sold in a month-Bar chart

c) To show the favorite flavor of the month -Pie chart

d) To show the temperature rise/fall in a month -Line chart

e) To show the most watched anime -Bar chart

f) To show the student count in each camp activity -Bar chart

g) To show the mark scored by a student in Math in all exams-Line chart

4) Identify the function


a) To plot a line graph - __plot()____________________

b) To plot a bar graph -____bar()__________________

Page 7 / 21
c) To plot a pie chart -___pie()___________________

d) To give a heading to the chart -___title()___________________

e) To label the x-axis of a graph - ___xlabel()___________________

f) To label the y-axis of a graph - ___ylabel()___________________

g) To create a random integer between 5 and 10 -

_____randint(5,10)_________________

h) To find the biggest number in the list L -

______max(L)________________

i) To add up the numbers in the list Marks -

______sum(Marks)________________

5) Mark as True or False.

a) Python is not case sensitive F

b) You can store different types of data in Python List T

c) append() is used to add elements to a list T

d) Round brackets ( ) is used to represent a Python list F

e) def is the keyword used to define a user defined T


function

f) You cannot store a list inside another list F

g) Indexing in Python list starts from 1 F

h) fillcolor() is used to change the pen color in Python turtle F


graphics

Page 8 / 21
i) pu() command to be used if you want to move the turtle T
without making any markings.

j) You can change the background color of the drawing T


screen

k) User defined function in Python can return only one F


variable.

l) It is compulsory to have at least one argument in Python F


user defined functions.

m) arange() is a function in numpy for creating a range of T


numbers

6) Write the Python code to get the following output.


Using range(), arange() or linspace() appropriately. Assume numpy
is imported.

a) 2 , 12, 22, 32,42


for i in range(2, 43, 10):
print (i,end=”, “)

b) 5, 10, 15, 20, 25, 30, 35, 40, 45,50,55,60


for i In range(5, 61, 5):
print (i,end=”, “)

c) 7, 14, 21, 28, 35, 42, 49, 56 , 63, 70


for i In range(7, 71, 7):
print (i,end=”, “)

Page 9 / 21
d) 10 9 8 7 6 5 4 3 2 1
for i In range(10, 0, -1):
print (i,end=” “)

e) 20 numbers between 5, 6
import numpy as np
numbers = np.linspace5, 6, 20)
print(numbers)

f) 1000 numbers between 0 and 50

import numpy as np
numbers = np.linspace(0, 50, 1000)
print(numbers)

7) Write the Python code to.


a) Read 20 numbers and add it a list Numbers.

Numbers=[ ]

b) Store the first 10 multiples of 5 into a list called Fives.

Fives=[ ]

Page 10 / 21
c) Read 30 numbers and store the even numbers into a list called Even.

Even=[ ]

d) Read the 5 marks scored in an exam and store it a list. Display the
total mark.

e) Read the cost of 20 items and display the total cost and average cost of
them.

Page 11 / 21
8) Write a user defined function in Python that accepts n and display the sum of
1st natural numbers

9) Write a user defined function that accepts a number. If the number is even,
reduce it to half. If the number is odd, square the number and add 1 to it.
Display the result.

Page 12 / 21
10) Write the Python code to get the following graphics.

a)

Base in brown and roof in green

Page 13 / 21
b) Set the pencolor as fb8500 and pen size as 5

c) Set the pen size as 2 and color as 9e2a2b

Page 14 / 21
d)

Page 15 / 21
11) Write the Python Program
a) A worm of 3.5 cm is making its progress towards an apple 20 cm away.
Display its progress after each movement until it enters the apple.

b) Prepare the Python program to make the following quiz question.


Who created Python ?
a. Bill Gates
b. Elon Musk
c. Guido Van Rossum
d. Steve Jobs
If the user answers a,b,or d, display the message : He is not
famous because of Python. If user answers c, display the
message: Correct answer, well done. If the user answers anything
else, display the message: Oh no! That is not an option at all.

Page 16 / 21
c) After the final exam, your computer science teacher wants to store all
your scores in a list. Teacher wants to find the highest mark and lowest
mark among all the students. Write a Python program for the same.

d) Read the height and weight of a person and calculate their BMI using
the formula: BMI = weight in kg/ (height x height) in m2. And display the
message as per the table.

Page 17 / 21
e) The entrance to the jumpy ride is only allowed for those who are taller
than 60 inches. When there are 8 people, a jumpy ride can be started.
Write a Python program that lets 8 people with 60 or more height into
the ride and then give a start ride message.

Page 18 / 21
12. Write the Python to get the following charts.
a) Solid line in olive color.

b) Dashed dot line style with marker

Page 19 / 21
c) Create 1000 linear spaced vectors between 0 & 50. Create sin values of the
vector, draw a line graph .

import ________________________
import numpy as np
x= np.linspace(____, ____,1000)
y= np.sin( )
plt. _________ (x,y)
plt.__________( “Sine Wave”)
plt. __________(“Vectors”)
plt.___________(“Sine Values”)
_____________________

d) Single color with half the width

Page 20 / 21
e) Colors used: Apple : red, mango : orange, Strawberry: crimson, kiwi: olive

Page 21 / 21

You might also like