Page 1 :
Chapter 8, , CONDITIONAL STATEMENTS, AND LOOPS IN PYTHON, , EXERCISE, A., 1., 2., 3., 4., 5., 6., , Fill in the blanks., For controlling the sequence of program control statements are used., Control statements are conditional and loop statements., Elif is the shortened way of saying else if., The while loop is used to iterate a block of code as long as the condition is true., Python assumes any non-zero and non-null values as True., The repetition of a set of statements is known as looping or iteration., , C., 1., 2., 3., 4., 5., , Write True (T) or False (F)., Ctrl + F is used to exit a loop., If the condition of while loop is always true, you get an infinite loop., Elseif statement is optional statement., If expression: loop(s) is the correct syntax for If statement., While loop is used when the number of times of iteration is not known., , C., 1., A., 2., A., , Short answer type questions., Mention two control statements., Control statements are of two types: loops and conditional statements., What condition will lead to an infinite loop?, If the condition of while loop is always True, it leads to an infinite loop. Press Ctrl + C to, exit from the loop., Write syntax for While loop., The While loop in Python is used to iterate a block of code as long as the condition is, true. The loop is used when you do not know the number of times to iterate., Syntax : while expression:, statement(s), Long answer type questions., Explain the difference between If and If…Else statement., The IF statement contains a logical expression using which data is compared and a, decision is made based on the result of the comparison., , 3., A., , D., 1., A., , F, T, T, F, T, , 21
Page 2 :
Syntax: if expression:, statement(s), An else statement can be combined with an if statement. An else statement contains the, block of code that executes if the conditional expression in the if statement resolves to, 0 or a FALSE value., Syntax: if expression:, statement(s), else:, statement(s), 2. Explain while loop with help of an example., A. The while loop in Python is used to iterate a block of code as long as the condition is, true. The loop is used when you do not know the number of times to iterate., Syntax: while expression:, statement(s), Following is a program to print numbers less than 10., num=l, while num<10:, print(num), num=num+ 1, E. Find the errors in the given code., 1. a =1, if a > 5:, print “This is incorrect.”, else:, print: “This is correct.”, Correct code:, a =1, if a > 5:, print (‘This is incorrect.’), else:, print ( ‘This is correct.’), 2. b = 0, while b < 40:, b=b+1, print a, Correct code:, b=0, while b < 40:, b=b+1, print b, 22