InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 51. |
How many important control structures are there in Python?(a) 3 (b) 4 (c) 5 (d) 6 |
|
Answer» There are 3 important control structures in Python |
|
| 52. |
How many types of looping constructs are there?(a) 1 (b) 2 (c) 3 (d) 4 |
|
Answer» There are 2 types of looping constructs |
|
| 53. |
Write note on range 0 in loop? |
|
Answer» Usually in Python, for loop uses the rangeQ function in the sequence to specify the initial, final and increment values. rangeQ generates a list of values starting from start till stop – 1. |
|
| 54. |
Give the syntax for ‘for loop’? |
|
Answer» for counter_variable in sequence: statements – block 1 [else: # optional block statements – block 2] |
|
| 55. |
Write a program to display ?AA BA B CA B C DA B C D E |
|
Answer» Program code: for i in range(1, 6): for i in range(65, 65 + i) a = chr (j) print a |
|
| 56. |
Executing a set of statements multiple times are called as ..........(a) Iteration(b) Looping(c) Branching (d) Both a and b |
|
Answer» (d) Both a and b |
|
| 57. |
How many blocks can be given in Nested if.. elif.. else statements?(a) 1(b) 2 (c) 3(d) n |
|
Answer» Answer is (d) n |
|
| 58. |
Write note on ifi. else structure? if .. else statement |
|
Answer» The if., else statement provides control to check the true block as well as the false block. Following is the syntax of ‘if.else’ statement. Syntax: if: statements – block 1 else: statements – block 2 |
|
| 59. |
Using if..else..elif statement check smallest of three numbers? |
|
Answer» num 1 = int (input(“Enter first number : “)) num 2 = int (input(“Enter second number : “)) num 3 = int (input(“Enter third number : “)) if (num 1 < num 2) and (num 1 < num 3): smallest = num 1 elif (num 2 < num 1) and (num 2 < num 3): smallest = num 2 else: smallest = num 3 print(” The smallest number is” , smallest) Output: Enter first number: 12 Enter second number: 7 Enter third number: 15 The smallest number is 7 |
|
| 60. |
elif can be considered to be abbreviation of ……(a) Nested if(b) If … else(c) Else if(d) If ……… Else |
|
Answer» (a) Nested if |
|
| 61. |
Write a program to check if a number is Positive, Negative or zero? |
|
Answer» num = int(input(“Enter a number : “)) if num > 0: print (“positive number”) elif num = = 0: print(“zero”) else: print (“Negative number”) Output: Enter a number: 2 positive number |
|
| 62. |
Write a program to check whether the given character is a vowel or not? |
|
Answer» ch = input(“Enter a character : “) if ch in (‘a’ , ’A’ , ‘e’ , ‘E’ , ‘i’ , ‘I’ , ‘o’, ‘O’ , ‘u’ , ‘U’): print (ch, ’is a vowel’) else: print (ch the letter is not a vowel’) Output: Enter a character: e e is a vowel |
|
| 63. |
Which one of the following is the entry check loop type?(a) While(b) Do while(c) If(d) If…else |
|
Answer» While is the entry check loop |
|
| 64. |
Write a program to check if the year is leap year or not? |
|
Answer» n = int (input(“Enter any year”)) if (n % 4 = 0): print “Leap Year” else: print “Not a Leap Year” Output: Enter any Year 2000 Leap Year |
|
| 65. |
Write a program to print the following pattern? |
|
Answer» Program: for i in range(0, 5): for j in range(5, i, -1): print (“*” , end = “”) print ( ) |
|
| 66. |
Using if..else..elif statement write a suitable program to display largest of 3 numbers. Display Largest of 3 Numbers? |
|
Answer» num 1 = int (input(“Enter first number : “)) num 2 = int (input(“Enter second number : “)) num 3 = int (input(“Enter third number : “)) if (num 1 > num 2) and (num 1 > num 3): largest = num 1 elif (num 2 > num 1) and (num 2 > num 3): largest = num 2 else: largest = num3 print (“The largest number is” , largest) Output: Enter first number: 7 Enter second number: 5 Enter third number: 4 The largest number is 7 |
|
| 67. |
Write a program to check if the given number is a palindrome or not? |
|
Answer» n = int(input(“Enter any Number : “)) temp = n rev = 0 while (n >0): dig = n%10 rev = rev * 10 + dig n = n // 10 if (temp = = rev): print (“palindrome”) else: print (“not a palindrome”) Output: Enter any Number 2332 palindrome |
|
| 68. |
Write a program to display all 3 digit odd numbers? |
|
Answer» Odd Number (3 digits) for a in range (100, 1000) if a % 2 = = 1: print b Output: 101, 103, 105, 107, .. …… 997, 999 |
|
| 69. |
Write a program to display sum of natural numbers, upto n? |
|
Answer» n = input(“Enter any number”) sum = 0 for i in range(i, n + 1): sum = sum + i print “sum = “ , sum Output: Enter any number 5 sum =15 |
|
| 70. |
Write a python program to display the following output.? |
|
Answer» i = 1 while (i< = 6): for j in range (1, i): print (j, end = \t’) print (end = ’\n’) i+ = 1f |
|