Python Paper
Python Paper
(Advanced Level)
Information & Communication Technology
Unit 09 – Programming
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
B = 18
(2) 22 if A < B and A != B:
ic
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
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
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
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
End
…………………………………………………………………………………………………
c) Write a pseudo-code corresponding to the logic in the flowchart for the above scenario.
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
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.
……………………………………………………………………………………………
……………………………………………………………………………………………
num = [13,27,32,38,51,65,88]
ic
for n in num:
if n >= 38:
print(n, end= ','))
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.
g
6. What is the difference between source code and object code?
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?
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
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.
ICT 8