0% found this document useful (0 votes)
0 views

Python Paper

The document contains a series of multiple choice and structured essay questions related to Information and Communication Technology, specifically focusing on programming concepts and Python language. It includes questions on programming constructs, data types, control structures, and algorithm design. Additionally, it features practical coding tasks and flowchart-related questions to assess understanding of programming logic.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Python Paper

The document contains a series of multiple choice and structured essay questions related to Information and Communication Technology, specifically focusing on programming concepts and Python language. It includes questions on programming constructs, data types, control structures, and algorithm design. Additionally, it features practical coding tasks and flowchart-related questions to assess understanding of programming logic.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

G.C.E.

(Advanced Level)
Information & Communication Technology

Unit 09 – Programming

Answer all questions.

g
Multiple Choice Questions

or
1. A computer program that converts an entire program into machine language is called a/an
……………….. .
(1) Interpreter (2) Simulator (3) Compiler (4) Commander (5) Linker

2. What is the value after executing the Python expression 16 / 2 ** 3 + 11 % 4?


s.
(1) 5.0 (2) 1 (3) 5 (4) 4.5 (5) 1.0

3. Which of the following is a valid Python identifier?


(1) tel no (2) tel-no (3) tel_no (4) tel#no (5) 4telno
te
4. What will be the output of the following loop?
for d in range (1,5,2):
print (“d” * 4, end=””)
no

(1) 4 12 20 (2) 4 12 (3) dddddddd


(4) dddd (5) dddd dddd
Dddd

5. What is the output of the following python code?


(1) 3 A = 5
t

B = 18
(2) 22 if A < B and A != B:
ic

(3) 3.4 B //= A


Print(B)
(4) 2 else:
A += B
(5) 5 Print(A)

6. Which of the following statements is false?


(1) Number, string, tuple, list and dictionary are standard data types in Python.
(2) A tuple can be deleted using del statement.
(3) Lists cannot be updated.
(4) A comma should be included in a tuple even though there is a single value.
(5) String value can be placed within single or double quotes.

ICT 1
7. What is printed by the following Python fragment?
s = "John Doe"
print (s[2:-1])
(1) n Doe (2) hn Doe (3) John (4) hn Do (5) error

8. What is the output of the following Python program fragment?


a = („45‟)
print (type(a))
(1) <class 'int'> (2) <class 'tuple'> (3) <class 'list'>
(4) <class 'number'> (5) <class 'str'>

g
9. Which of the following Python programs are syntactically correct?
(1) a = 6; (2) a = 6 (3) a = 6
if a == 5; if a == 5: if a = = 5:

or
print(“five”); print(“five”)

(4) a = 6 (5) a = 6
if a = 5: if a = = 5;
print(“five”) Display (“five”)

(1) 4
s.
10. What is the value of sum after the following loop terminates?
sum = 0
item = 0
(2) 5
while item < 5:
te
(3) 6 item += 1
sum += item
(4) 7 if sum > 4: break
print(sum)
(5) 8
no

11. Which of the following is a valid Python statement that can be used to open a file called
“output.txt” so that new data can be added to the end of the file without deleting its original
conent?
(1) open = file2 ("output.txt", "r") (2) file2 = open("output.txt", "r")
t

(3) file2 = open("output.txt", "a") (4) open = file2 (“output.txt”, “a”)


(5) file2 = open(“output.txt”, “w”)
ic

12. Consider the following Python statements:


a = input (“enter a number”)
b = {1:2, „b‟: 2},{„age‟: 21}
c = [„a‟,2,(1,2,3)]
What are the data types of the variables a, b and c, respectively?
(1) List, Dictionary, List (2) String, Tuple, List (3) Integer, Tuple, List
(4) String, Dictionary, List (5) Integer, Dictionary, Tuple

ICT 2
 Use the following flowchart to answer the questions 13 and 14.

Start

a =0

No
a>6? a=a+2

Yes

g
Print a

or
Stop

13. What is the output of the algorithm represented by this flowchart?


(1) 0 (2) 6 s. (3) 8 (4) 10 (5) 12

14. Which of the following Python programs correctly represents this flowchart?
(1) a = 0 (2) a = 0
while (a>6): while (a>6):
te
a = a + 1 a = a + 1
print(a) print(a)

(4) a = 0 (3) a = 0
while not(a>6): while not(a>6):
no

a = a + 1 a = a + 1
print(a) print(a)

(5) a = 0
While (a<=6):
a = a + 1
t

print(a)
ic

15. Suppose you have the following list of numbers to sort in ascending order:
[11, 7, 12, 14, 19, 1, 6, 18, 8, 20]
Which list represents the partially sorted list after three complete passes of bubble sort?
(1) [7, 11, 12, 1, 6, 14, 8, 18, 19, 20] (2) [7, 11, 12, 14, 19, 1, 6, 18, 8, 20]
(3) [11, 7, 12, 14, 1, 6, 8, 18, 19, 20] (4) [11, 7, 12, 14, 8, 1, 6, 18, 19, 20]
(5) [11, 7, 12, 8, 1, 6, 14, 18, 19, 20]

ICT 3
Structured Essay Questions

1. Following flowchart represents an algorithm for calculating the bill of a customer and
printing total value and number of items purchased. If total amount of the bill exceeds
Rs.2000, 10% discount is given.

Start

total = 0, quantity = 0, d = 0

g
No
Are there
more items?

or
Yes
No
Is total > 2000 ?
Input item price p
s. Yes

quantity = quantity + 1 d = total * 10 / 100

total = total + p total = total - d


te
Print total, quantity
no

End

a) Name the variables used in the above flowchart.


…………………………………………………………………………………………………
t

b) Write the control structures used in the above flowchart.


ic

…………………………………………………………………………………………………

c) Write a pseudo-code corresponding to the logic in the flowchart for the above scenario.
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………

Nalanda College – Colombo ICT 4


2. Consider the following Python code segment.
sum = 0
for i in range(0, 18, 3):
if i%6 == 0 :
sum = sum + i
print(i)
print(sum)

a) What is the value of sum after the following code has been executed?
…………………………………………………………………………………………………

g
b) Rewrite the above code using a while loop without using break statements and without
introducing any more variables.
…………………………………………………………………………………………………

or
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
s.
3. Write Python statements to do the following considering the values given below.
25, 50, 75, red, blue
te
a) Add the above items into a list.
……………………………………………………………………………………………

b) Delete the element 50 from the list.


no

……………………………………………………………………………………………

c) Insert an integer value 100 after 75.


……………………………………………………………………………………………

4. Consider the following Python code segment.


t

num = [13,27,32,38,51,65,88]
ic

for n in num:
if n >= 38:
print(n, end= ','))

a) What is the output of the above program?


…………………………………………………………………………………………………

b) What is the purpose of this program?


…………………………………………………………………………………………………
…………………………………………………………………………………………………

ICT 5
5. Write the outputs of the following Python code fragments.
a) num = [13,27,32,38,51,65,88]
for n in num:
if n >= 38:
print(n, end= ','))

……………………………………………………………………………………………

b) a = 3
b = 2
print (a * 5 + 2 % 4 >> 1)

g
……………………………………………………………………………………………
c) s = "Hello World"

or
print (s[3:-2])

……………………………………………………………………………………………

d) m = 100 s.
n = 200
def func (x, y):
global m
m += x * y
te
n = m + x + y
return
func (10,5)
print(m+n)
no

……………………………………………………………………………………………
t
ic

ICT 6
Essay Questions

1. Give three features of first generation, second generation and third generation languages
separately.

2. State two differences between imperative and declarative programming paradigms.

3. Explain the need of language translators in computer programming.


4. Compare and contrast interpreter and compiler.

5. Briefly describe the function of a linker.

g
6. What is the difference between source code and object code?

7. What is the purpose of using comments in a program?

or
8. State the three flow control structures used in programming and show them using a flow
chart.

9. Explain the difference between for loop and while loop using examples.

Begin
A = 12
s.
10. Find the output of the following algorithm using a dry run (hand traces).

Do While A > 3
te
A = A -2
End While
Display A
End
no

11. Write algorithms to solve the problems given below in the form of a flowchart and write
programs in Python to implement each algorithm.
a) Read three numbers and find the largest number.
b) Find and display the average ICT marks of ten students. The program should read one
mark at a time.
t

c) Read a set of numbers until a negative number is entered and print the sum of even
ic

numbers in it.
d) Read a set of 20 integers and display the number of odd numbers in it.
e) Read marks obtained for English by students in a class and print the highest and lowest
mark. Program should read the number of students at the beginning of the program and
one mark should be read at a time.

ICT 7
12. The following Python program is intended to print a set of words entered by the user as a
single line. The program prompts the user to enter the words until an empty line is entered.
The words should be printed in the entered order. The program has both syntax and logical
errors. The line numbers are used to reference the lines and not part of the program.

1. wd = raw_input("Type a word:>)
2. line = ""
3. while wd !== "":
4. line = wd + line + " "
5. wd = raw_input("Type a word:> )
6. print("You typed: ", line)

g
a) State the lines which contain syntax errors and state the error.
b) Which lines should be changed to obtain the desired output and state how they should be

or
changed?

13. Write Python programs for the following using Functions.


a. Calculate the perimeter of a rectangle.
b. Calculate volume of a cylinder.
s.
c. Display the largest number from two given numbers.
d. Display sum of numbers from 1 to a given number.

14. Draw a flowchart to read all the lines in the file “data.txt” one by one and print them on the
te
screen. Write the Python program to implement the algorithm.

15. Nilani has recorded the ICT marks obtained by 20 students for a test in the computer. Marks
are stored in the file „marks.txt‟ where each mark is written in a separate line as given
below.
no

name1 mark1
name2 mark2
…….. …….
Nilani requested you to write a program to find the number of students who got marks
greater than 50 and print it on the screen.
t

a) Write an algorithm for the above problem using a flowchart.


b) Write a Python program to implement your flowchart.
ic

16. Draw a flowchart to input a list of integers and search a user given integer from the list.
Write a program in Python to implement the flowchart.

Prepared by : Ms. Imalka Dissanayaka

ICT 8

You might also like