161 solutions available
Question 1The if statement forms the selection construct in Python.
Question 2The pass statement is a do nothing statement in Python.
Question 3The for and while statements form the repetition construct in Python.
Question 4Three constructs that govern the flow of control are sequence, selection/decision and repetition/iteration.
Question 5In Python, indentation defines a block of statements.
Question 6An if-else statement has less number of conditional checks than two successive ifs.
Question 7The in operator tests if a given value is contained in a sequence or not.
Question 8The two membership operators are in and not in.
Question 9An iteration refers to one repetition of a loop.
Question 10The for loop iterates over a sequence.
Question 11The while loop tests a condition before executing the body-of-the-loop.
Question 12The else clause can occur with an if as well as with loops.
Question 13The else block of a loop gets executed when a loop ends normally.
Question 14The else block of a loop will not get executed if a break statement has terminated the loop.
Question 15The break statement terminates the execution of the whole loop.
Question 16The continue statement terminates only a single iteration of the loop.
Question 17The break and continue statements, together are called jump statements.
Question 18In a nested loop, a break statement inside the inner loop, will terminate the inner loop only.
Question 1In a Python program, a control structure:directs the order of execution of the statements in the program ✓dictates what happens before the...
Question 2An empty/null statement in Python isgopass ✓over;
Question 3The order of statement execution in the form of top to bottom, is known as .......... construct.selectionrepetitionsequence ✓flow
Question 4The .......... construct allows to choose statements to be executed, depending upon the result of a condition.selection...
Question 5The .......... construct repeats a set of statements a specified number of times or as long as a condition is true.selectionrepetition...
Question 6Which of the following statements will make a selection construct?if ✓if-else ✓forwhile
Question 7Which of the following statements will make a repetition construct?ifif-elsefor ✓while ✓
Question 8In Python, which of the following will create a block in a compound statement ?colonstatements indented at a lower, same level ✓indentation...
Question 9What signifies the end of a statement block or suite in Python ?A comment}endA line that is indented less than the previous line ✓
Question 10Which one of the following if statements will not execute successfully ?if (1, 2) : print('foo')if (1, 2) print('foo') ✓if (1, 2)...
Question 11What does the following Python program display ?x = 3 if x == 0: print ("Am...
Question 12If the user inputs : 2<ENTER>, what does the following code snippet print?x = float(input()) if(x==1): print("Yes") elif (x...
Question 13Consider the following code segment:a = int(input("Enter an integer: ")) b = int(input("Enter an integer: ")) if a <= 0: b = b +1...
Question 14Consider the following code segment:a = int(input("Enter an integer: ")) b = int(input("Enter an integer: ")) if a <= 0: b = b +1...
Question 15Consider the following code segment:a = int(input("Enter an integer: ")) b = int(input("Enter an integer: ")) if a <= 0: b = b +1...
Question 16Consider the following code segment:a = int(input("Enter an integer: ")) b = int(input("Enter an integer: ")) if a <= 0: b = b +1...
Question 17Consider the following code segment:a = int(input("Enter an integer: ")) b = int(input("Enter an integer: ")) if a <= 0: b = b +1...
Question 18What values are generated when the function range(6, 0, -2) is executed ?[4, 2][4, 2, 0][6, 4, 2] ✓[6, 4, 2, 0][6, 4, 2, 0, -2]
Question 19Which of the following is not a valid loop in Python ?forwhiledo-while ✓if-else ✓
Question 20Which of the following statement(s) will terminate the whole loop and proceed to the statement following the loop ?passbreak ✓continuegoto
Question 21Which of the following statement(s) will terminate only the current pass of the loop and proceed with the next iteration of the...
Question 22Function range(3) is equivalent to :range(1, 3)range(0, 3) ✓range(0, 3, 1) ✓range(1, 3, 0)
Question 23Function range(3) will yield an iteratable sequence like[0, 1, 2] ✓[0, 1, 2, 3][1, 2, 3][0, 2]
Question 24Function range(0, 5, 2) will yield on iterable sequence like[0, 2, 4] ✓[1, 3, 5][0, 1, 2, 5][0, 5, 2]
Question 25Function range(10, 5, -2) will yield an iterable sequence like[10, 8, 6] ✓[9, 7, 5][6, 8, 10][5, 7, 9]
Question 26Function range(10, 5, 2) will yield an iterable sequence like[] ✓[10, 8, 6][2, 5, 8][8, 5, 2]
Question 27Consider the loop given below :for i in range(-5) : print(i)How many times will this loop run?50 ✓infiniteError
Question 28Consider the loop given below :for i in range(10, 5, -3) : print(i)How many times will this loop run?32 ✓1Infinite
Question 29Consider the loop given below :for i in range(3) : passWhat will be the final value of i after this loop ?012 ✓3
Question 30Consider the loop given below :for i in range(7, 4, -2) : breakWhat will be the final value of i after this loop ?457 ✓-2
Question 31In for a in __________ : , the blank can be filled withan iterable sequence ✓a range( ) function ✓a single valuean expression
Question 32Which of the following are entry controlled loops ?ifif-elsefor ✓while ✓
Question 33Consider the loop given below. What will be the final value of i after the loop?for i in range(10) : break100 ✓Error9
Question 34The else statement can be a part of .......... statement in Python.if ✓defwhile ✓for ✓
Question 35Which of the following are jump statements ?ifbreak ✓whilecontinue ✓
Question 36Consider the following code segment :for i in range(2, 4): print(i)What values(s) are printed when it executes?232 and 3 ✓3 and 42, 3...
Question 37When the following code runs, how many times is the line "x = x * 2" executed?x = 1 while ( x < 20 ): x = x * 225 ✓19432
Question 38What is the output when this code executes ?x = 1 while (x <= 5): x + 1 print(x)6145no output ✓
Question 39How many times does the following code execute ?x = 1 while (x <= 5): x + 1 print (x)6145infinite ✓
Question 40What is the output produced when this code executes?i = 1 while (i <= 7): i*= 2 print (i)8 ✓16414no output
Question 41Consider the following loop:j = 10 while j >= 5: print("X") j=j-1Which of the following for loops will generate the same output...
Question 42What is the output produced when this code executes?a = 0 for i in range(4,8): if i % 2 == 0: a = a + i print (a) 4810 ✓18
Question 43Which of the following code segments contain an example of a nested loop?for i in range(10): print(i)for j in range(10): print(j)for...
Question 1An if-else tests less number of conditions than two successive ifs.True
Question 2A for loop is termed as a determinable loop.True
Question 3The while loop is an exit controlled loop.False
Question 4The range( ) creates an iterable sequence.True
Question 5The for loop can also tests a condition before executing the loop-body.False
Question 6Only if statement can have an else clause.False
Question 7A loop can also take an else clause.True
Question 8The else clause of a loop gets executed only when a break statement terminates it.False
Question 9A loop with an else clause executes its else clause only when the loop terminates normally.True
Question 10A loop with an else clause cannot have a break statement.False
Question 11A continue statement can replace a break statement.False
Question 12For a for loop, an equivalent while loop can always be written.True
Question 13For a while loop, an equivalent for loop can always be written.False
Question 14The range( ) function can only be used in for loops.False
Question 15An if-elif-else statement is equivalent to a nested-if statement.True
Question 1What is the common structure of Python compound statements?AnswerThe common structure of a Python compound statement is as shown...
Question 2What is the importance of the three programming constructs?AnswerThe importance of the three programming constructs is a given...
Question 3What is empty statement in Python? What is its need?AnswerIn Python, an empty statement is pass statement. Its syntax is:passWhen pass...
Question 4Which Python statement can be termed as empty statement?AnswerIn Python, an empty statement is pass statement. Its syntax is:pass
Question 5What is an algorithm?AnswerAn algorithm is defined as the sequence of instructions written in simple English that are required to get the...
Question 6What is a flowchart? How is it useful?AnswerA flowchart is a pictorial representation of an algorithm. It uses boxes of different shapes to...
Question 7Draw flowchart for displaying first 10 odd numbers.Answer
Question 8What is entry-controlled loop?AnswerAn entry-controlled loop checks the condition at the time of entry. Only if the condition is true, the...
Question 9What are the four elements of a while loop in Python?AnswerThe four elements of a while loop in Python are:Initialization Expressions — It...
Question 10What is the difference between else clause of if-else and else clause of Python loops?AnswerThe else clause of an if-else statement is...
Question 11In which cases, the else clause of a loop does not get executed?AnswerThe else clause of a loop does not get executed if the loop is...
Question 12What are jump statements? Name them.AnswerJump statements are used to unconditionally transfer program control to other parts within a...
Question 13How and when are named conditions useful?AnswerSometimes the conditions being used in the code are complex and repetitive. In such cases,...
Question 14What are endless loops ? Why do such loops occur?AnswerA loop which continues iterating indefinitely and never stops is termed as an...
Question 15How is break statement different from continue?AnswerWhen the break statement gets executed, it terminates its loop completely and control...
Question 1Rewrite the following code fragment that saves on the number of comparisons:if (a == 0) : print ("Zero") if (a == 1) : print ("One")...
Question 2Under what conditions will this code fragment print "water"?if temp < 32 : print ("ice") elif temp < 212: print...
Question 3What is the output produced by the following code?x = 1 if x > 3 : if x > 4 :...
Question 4What is the error in following code? Correct the code:weather = 'raining' if weather = 'sunny' : print ("wear sunblock") elif...
Question 5What is the output of the following lines of code?if int('zero') == 0 : print ("zero") elif str(0) == 'zero' :...
Question 6Find the errors in the code given below and correct the code:if n == 0 print ("zero") elif : n == 1 print ("one") elif...
Question 7What is following code doing? What would it print for input as 3?n = int(input( "Enter an integer:" )) if n < 1 : print ("invalid...
Question 8How are following two code fragments different from one another? Also, predict the output of the following code fragments :(a)n =...
Question 9aRewrite the following code fragment using for loop:i = 100 while (i > 0) : print (i) i -= 3Answerfor i in range(100, 0, -3) :...
Question 9bRewrite the following code fragment using for loop:while num > 0 : print (num % 10) num = num/10Answerl = [1] for x in l:...
Question 9cRewrite the following code fragment using for loop:while num > 0 : count += 1 sum += num num –= 2 if count ==...
Question 10aRewrite following code fragment using while loops :min = 0 max = num if num < 0 : min = num max = 0 # compute sum of integers...
Question 10bRewrite following code fragment using while loops :for i in range(1, 16) : if i % 3 == 0 : print (i)Answeri = 1 while i <...
Question 10cRewrite following code fragment using while loops :for i in range(4) : for j in range(5): if i + 1 == j or j + 1 == 4 :...
Question 11aPredict the output of the following code fragments:count = 0 while count < 10: print ("Hello") count +=...
Question 11bPredict the output of the following code fragments:x = 10 y = 0 while x > y: print (x, y) x = x - 1 y = y + 1AnswerOutput10...
Question 11cPredict the output of the following code fragments:keepgoing = True x=100 while keepgoing : print...
Question 11dPredict the output of the following code fragments:x = 45 while x < 50 : print (x)AnswerThis is an endless (infinite) loop that...
Question 11ePredict the output of the following code fragments:for x in [1,2,3,4,5]: print (x)AnswerOutput1 2 3 4 5 Explanationx will be assigned...
Question 11fPredict the output of the following code fragments:for x in range(5): print (x) AnswerOutput0 1 2 3 4 Explanationrange(5) will...
Question 11gPredict the output of the following code fragments:for p in range(1,10): print (p) AnswerOutput1 2 3 4 5 6 7 8 9...
Question 11hPredict the output of the following code fragments:for q in range(100, 50, -10): print (q)AnswerOutput100 90 80 70 60...
Question 11iPredict the output of the following code fragments:for z in range(-500, 500, 100): print (z)AnswerOutput-500 -400 -300 -200 -100 0...
Question 11jPredict the output of the following code fragments:for y in range(500, 100, 100): print (" * ", y)AnswerThis code generates No...
Question 11kPredict the output of the following code fragments:x = 10 y = 5 for i in range(x-y * 2):...
Question 11lPredict the output of the following code fragments:for x in [1,2,3]: for y in [4, 5, 6]: print (x, y)AnswerOutput1 4 1 5 1 6...
Question 11mPredict the output of the following code fragments:for x in range(3): for y in range(4): print (x, y, x +...
Question 11nPredict the output of the following code fragments:c = 0 for x in range(10): for y in range(5): c += 1 print...
Question 12What is the output of the following code?for i in range(4): for j in range(5): if i + 1 == j or j + i == 4: print ("+",...
Question 13In the nested for loop code below, how many times is the condition of the if clause evaluated?for i in range(4): for j in range(5):...
Question 14Which of the following Python programs implement the control flow graph shown?(a)while True : n = int(input("Enter an int:")) if n...
Question 15Find the error. Consider the following program :a = int(input("Enter a value: ")) while a != 0: count = count + 1 a =...
Question 1Write a Python script that asks the user to enter a length in centimetres. If the user enters a negative length, the program should tell...
Question 2A store charges ₹120 per item if you buy less than 10 items. If you buy between 10 and 99 items, the cost is ₹100 per item. If you buy 100...
Question 3Write a program that reads from user — (i) an hour between 1 to 12 and (ii) number of hours ahead. The program should then print the time...
Question 4Write a program that asks the user for two numbers and prints Close if the numbers are within .001 of each other and Not close...
Question 5A year is a leap year if it is divisible by 4, except that years divisible by 100 are not leap years unless they are also divisible by 400....
Question 6Write a program to input length of three sides of a triangle. Then check if these sides will form a triangle or not.(Rule is:...
Question 7Write a short program to input a digit and print it in words.Solutiond = int(input("Enter a digit(0-9): ")) if d == 0 : print("Zero")...
Question 8Write a short program to check whether square root of a number is prime or not.Solutionimport math n = int(input("Enter a number: ")) sr =...
Question 9Write a short program to print first n odd numbers in descending order.Solutionn = int(input("Enter n: ")) x = n * 2 - 1 for i in range(x,...
Question 10Write a short program to print the following series :(i) 1 4 7 10 .......... 40.(ii) 1 -4 7 -10 .......... -40Solutionprint("First...
Question 11Write a short program to find average of list of numbers entered through keyboard.Solutionsum = count = 0 print("Enter numbers")...
Question 12Write a program to input 3 sides of a triangle and print whether it is an equilateral, scalene or isosceles triangle.Solutiona =...
Question 13Write a program to take an integer a as an input and check whether it ends with 4 or 8. If it ends with 4, print "ends with 4", if it ends...
Question 14Write a program to take N (N > 20) as an input from the user. Print numbers from 11 to N. When the number is a multiple of 3, print...
Question 15Write a short program to find largest number of a list of numbers entered through keyboard.Solutionprint("Enter numbers:") print("(Enter...
Question 16Write a program to input N numbers and then print the second largest number.Solutionn = int(input("How many numbers you want to enter? "))...
Question 17Given a list of integers, write a program to find those which are palindromes. For example, the number 4321234 is a palindrome as it reads...
Question 18Write a complete Python program to do the following :(i) read an integer X.(ii) determine the number of digits n in X.(iii) form an...
Question 19Write a Python program to print every integer between 1 and n divisible by m. Also report whether the number that is divisible by m is...
Question 20aWrite Python programs to sum the given sequences:2/9 - 5/13 + 8/17 ...... (print 7 terms)Solutionn = 2 #numerator initial value d = 9...
Question 20bWrite Python programs to sum the given sequences:12 + 32 + 52 + ..... + n2 (Input n)Solutionn = int(input("Enter the value of n: ")) i =...
Question 21Write a Python program to sum the sequence:1 + 1/1! + 1/2! + 1/3! + ..... + 1/n! (Input n)Solutionn = int(input("Enter the value of n: "))...
Question 22Write a program to accept the age of n employees and count the number of persons in the following age group:(i) 26 - 35(ii) 36 -...
Question 23aWrite programs to find the sum of the following series:x - x2/2! + x3/3! - x4/4! + x5/5! - x6/6! (Input x)Solutionx = int(input("Enter...
Question 23bWrite programs to find the sum of the following series:x + x2/2 + x3/3 + ...... + xn/n (Input x and n both)Solutionx = int(input("Enter...
Question 24aWrite programs to print the following shapes: * * * * * * * * *Solutionn = 3 # number of rows # upper half for i in range(n) :...
Question 24bWrite programs to print the following shapes:** ** * ** **Solutionn = 3 # number of rows # upper half for i in range(n) : for k in...
Question 24cWrite programs to print the following shapes: * * ** * * * *Solutionn = 3 # number of rows # upper half for i in range(1, n+1)...
Question 24dWrite programs to print the following shapes:** ** ** ** ** **Solutionn = 4 # number of row #upper half for i in range(1, n+1) :...
Question 25aWrite programs using nested loops to produce the following patterns:AA BA B CA B C DA B C D EA B C D E FSolutionn = 6 for i in range(n)...
Question 25bWrite programs using nested loops to produce the following patterns:AB BC C CD D D DE E E E ESolutionn = 5 t = 65 for i in range(n) :...
Question 25cWrite programs using nested loops to produce the following patterns:02 24 4 46 6 6 68 8 8 8 8Solutionfor i in range(0, 10, 2): for j...
Question 25dWrite programs using nested loops to produce the following patterns:24 46 6 68 8 8 8Solutionfor i in range(2, 10, 2) : for j in...
Question 26Write a program using nested loops to produce a rectangle of *'s with 6 rows and 20 *'s per row.Solutionfor i in range(6) : for j in...
Question 27Given three numbers A, B and C, write a program to write their values in an ascending order. For example, if A = 12, B = 10, and C = 15,...
Question 28Write a Python script to input temperature. Then ask them what units, Celsius or Fahrenheit, the temperature is in. Your program should...
Question 29Ask the user to enter a temperature in Celsius. The program should print a message based on the temperature:If the temperature is less...
Question 30Write a program to display all of the integers from 1 up to and including some integer entered by the user followed by a list of each...