# 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).

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)

ans. (a) 6 (b) 0

# Q 8. Consider the following Python Program, intended to calculate factorial :number = int(input(“Enter number”))n, result = number, 1while True or n :result = result * nn = n — 1factorial = resultprint(“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

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