Conditional And Iterative Statements Important Questions class 11 computer science with python

Conditional And Iterative Statements important questions class 11 Computer Science with Python

Conditional And Iterative Statements

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 determined before-hand as the size of the sequence, it is operating upon.
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 ?

ans. FALSE
TRUE

Q 6. Write Python code to add the odd numbers up to (and including) a given value N and print the result.

ans.
N = int(input(‘Enter number’))
sum = 0
i = 1
while i <= N :
sum = sum + i
i = i + 2
print(sum)

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
print(sum)

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)

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 :
:
or
while n>0 :
:

Q 9. Write Python script to print the following pattern :
1
1 3
1 3 5
1 3 5 7

ans.
for a in range(3, 10, 2) :
for b in range(1, a, 2) :
print (b, end = ‘ ‘)
print()

Q10. Write a program to print the following using a single loop (no nested loops)
1
1 1
1 1 1
1 1 1 1
1 1 1 1 1

ans.
n = 1
for a in range(5) :
print(n)
n = n*10+1

Conditional And Iterative Statements notes class 11 conditional and iterative statements in details

Originally published at https://kamalsinghstarbooks.xyz on January 24, 2021.