Conditional And Iterative Statements important questions class 11 Computer Science with Python
Q 1. What is a statement ? What is the significance of an empty statements ?
ans. A statement is an instruction given to the computer to perform any kind of action. An empty statement is useful in situations where the code requires a statement but logic does not. To Python offers pass statement as an empty statement. (Conditional And Iterative Statements)
Q 2. If you are asked to label the Python loops as determinable or non-determinable, Which label would you give to which loop ? Justify your answer.
ans. The ‘for loop’ can be labelled as determinable loop as number of its iterations can be detemined before-hand as the size of the sequence, it is operating opon.
The ‘while loop’ can be labelled as non-determinable loop, as its number of iterations cannot be determined before-hand. Its iterations depend upon the result of a test-condition, which cannot be determined before-hand.
Q 3.There are two types of else clauses in python. What are these two types of else clause ?
ans. The two types of Python else clauses are :
(a) else in an if statement (b) else in a loop statement
The else clause of an if statement is executed when the condition of the if statement results into false. The else clause of a loop is executed when the loop is terminating normally i.e., when its test-condition has gone false for a while loop or when the for loop has executed for the last value in sequence.
Q 4. Use the Python range() function to create the following list :[7,3,-1,-5].
ans. range(7, -6, -4).
Q 5. What is the output of following code ?
if (4+5 == 10) :
Q 6. Write Python code to add the odd numbers up to (and including) a given value N and print the result.
N = int(input(‘Enter number’))
sum = 0
i = 1
while i <= N :
sum = sum + i
i = i + 2
Q 7.Consider the following Python program :
N = int(input(“Enter N :”))
i = 1
sum = 0
while i < N :
if i%2 ==0 :
sum = sum + i
i = i + 1
(a) What is the output when the input value is 5 ?
(b) What is the output when the input value is 0 ?
ans. (a) 6 (b) 0
Q 8. Consider the following Python Program, intended to calculate factorial :
number = int(input(“Enter number”))
n, result = number, 1
while True or n :
result = result * n
n = n – 1
factorial = result
print(“factorial of”, number, “is”, factorial)
(a) What happens when the user enters a value of 5 ?
(b) How would you fix this program ?
ans. The problem is that the program will repeat infinitely.
The problem lies with the condition of while loop this condition will never go false.
correct condition will be any of these :
while n :
while n>0 :
Q 9. Write Python script to print the following pattern :
2. 1 3
3. 1 3 5
4. 1 3 5 7
for a in range(3, 10, 2) :
for b in range(1, a, 2) :
print (b, end = ‘ ‘)
Q10. Write a program to print the following using a single loop (no nested loops)
2. 1 1
3. 1 1 1
4. 1 1 1 1
5. 1 1 1 1 1
n = 1
for a in range(5) :
n = n*10+1