Professional Documents
Culture Documents
ICT G6 Sem2 Finals Revision
ICT G6 Sem2 Finals Revision
ICT G6 Sem2 Finals Revision
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
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”
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
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
Page 7 / 21
c) To plot a pie chart -___pie()___________________
_____randint(5,10)_________________
______max(L)________________
______sum(Marks)________________
Page 8 / 21
i) pu() command to be used if you want to move the turtle T
without making any markings.
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)
import numpy as np
numbers = np.linspace(0, 50, 1000)
print(numbers)
Numbers=[ ]
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)
Page 13 / 21
b) Set the pencolor as fb8500 and pen size as 5
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.
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.
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”)
_____________________
Page 20 / 21
e) Colors used: Apple : red, mango : orange, Strawberry: crimson, kiwi: olive
Page 21 / 21