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. |
Write a Python script that display first ten Mersenne numbers. Mersenne number are in the form of 2n-1 |
|
Answer» def Mersenne (n): return 2**n-1 print “First ten Mersenne numbers are :” for a in range (1,11): print Mersenne (a) |
|
| 52. |
Create a function doubleFactorial(n) that takes an odd integer and returns the product of all odd values upto the value n (where n=2k-l). |
|
Answer» def doubleFactorial(num): product = 1 i = 0 k = 0 while k <num: k = 2*i+l product * = k i += 1 return product |
|
| 53. |
Create a function factorial(x) that takes an integer and returns the product of all the positive integers less than or equal to n. |
|
Answer» def factorial(num): product =1 i = num while i > 0: product *=i i-=l return product |
|
| 54. |
Write Python script to print the following pattern11 11 1 11 1 1 11 1 1 1 1 |
|
Answer» n = 1 for a in range (5) : print n n = n *10 + 1 |
|
| 55. |
Write Python script to calculate sum of following series :s = (1) + (1+2) + (1+2+3) +…+ (1+2+3+…+n) |
|
Answer» sum 0 n = int (raw_input (“Enter the value of n :”)] for a in range (2, n+2): term = 0 for b in range (1,1): term + = b print “Term”, (a-1), “:”,term sum + = term print “Sum of”, n, “term is”, sum |
|
| 56. |
Create a function add Numbers(x) that takes a number as an argument and adds all the integers between 1 and the number (inclusive) and returns the total number. |
|
Answer» def add Numbers (num): total = 0 i = 1 while i< = num: total + = i i+ = 1 return total |
|
| 57. |
Which numbers are printed?for i in range(2):print ifor i in range(4,6):print i |
|
Answer» 0,1,4,5 number are printed. |
|
| 58. |
Does Python support “switch” statements? |
|
Answer» No, Python does not currently support switch or case statements as in other languages. |
|
| 59. |
What is a statement ? What is the significance of an empty statement ? |
|
Answer» 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 does not require logic. To fill these two requirements simultaneously, an empty statement is used. Python offers a‘pass’ statement as an empty statement. |
|
| 60. |
What is the difference between determinable loop and non-determinable loop ? |
|
Answer» The ‘for loop’ can be labeled as ‘determinable Ans. Value of expression is 100 Goodbye! 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 ‘non-determined 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. |
|