Page 15 - IPP-11
P. 15
QUESTION 5
(a) What is pseudo code? How is it useful in developing logic for the solution of a problem? (1)
Ans. Pseudo code is an informal way of describing the steps of a program’s solution without using any strict
programming language syntax.
It gives an idea as to how algorithm works and how control flows from one step to another.
(b) Write four elements of “while” loop in Python. (1)
Ans. (i) Initialization expression
(ii) Test expression
(iii) Body of the loop
(iv) Update expression
(c) Identify and correct the problem with the following code– (1)
countdown=10
while countdown > 0:
print(countdown, end=' ')
countdown = 1
print("Finally.")
Ans. It is an infinite loop due to non-updation of the variable countdown.
(d) Draw a flow chart for displaying the first 100 odd numbers. (2)
Ans.
Start
Assign i=0
Whether i=100 Yes
reached?
No
False
if i%2!=0
True
Print i
Compute i=i+1
Stop
(e) Write a Python script to print the first 20 elements of the ‘Fibonacci series’. Some initial elements of the
series are: 0 1 1 2 3 5 8 . . . (2)
Ans. nterms = int(input("How many terms?"))
n1 = 0
n2 = 1
count = 0
print("Fibonacci sequence upto",nterms,":")
while count < nterms:
print(n1,end=',')
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
5