43 solutions available
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)816414no 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) 481018
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 9What are the four elements of a while loop in Python?
Question 1Rewrite the following code fragment that saves on the number of comparisons:if (a == 0) : print ("Zero") if (a == 1) : print ("One")...
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 6Find the errors in the code given below and correct the code:if n == 0 print ("zero") elif : n == 1 print ("one") elif...
Question 8How are following two code fragments different from one another? Also, predict the output of the following code fragments :(a)n =...
Question 9bRewrite the following code fragment using for loop:while num > 0 : print (num % 10) num = num/10
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)
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 11bPredict the output of the following code fragments:x = 10 y = 0 while x > y: print (x, y) x = x - 1 y = y + 1
Question 11fPredict the output of the following code fragments:for x in range(5): print (x)
Question 11gPredict the output of the following code fragments:for p in range(1,10): print (p)
Question 11hPredict the output of the following code fragments:for q in range(100, 50, -10): print (q)
Question 11kPredict the output of the following code fragments:x = 10 y = 5 for i in range(x-y * 2):...
Question 11mPredict the output of the following code fragments:for x in range(3): for y in range(4): print (x, y, x + y)
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 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 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 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 15Write a short program to find largest number of a list of numbers entered through keyboard.Solutionprint("Enter numbers:") print("(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 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 24aWrite programs to print the following shapes: * * * * * * * * *Solutionn = 3 # number of rows # upper half for i in range(n) :...
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 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...