Explore topic-wise InterviewSolutions in Current Affairs.

This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.

1.

How many types of functions arguments are there? (a) 2(b) 3(c) 4(d) 5

Answer»

There are 4 types of functions arguments.

2.

How many methods of arguments passing are there in variable length method.(a) 2(b) 3(c) 4(d) 5

Answer»

There are 2 methods of arguments passing in variable length method.

3.

Define global scope?

Answer»

A variable, with global scope can be used anywhere in the program. It can be created by defining a variable outside the scope of any function/block.

4.

Evaluate the following functions and write the output?S.no.Functionoutput1eval('25*2-5*4')2math.sqrt(abs(81))3math.ceil(3.54+4.6)4math.floor(3.5 + 4.6)

Answer»
S.no.Functionoutput
1eval('25*2-5*4')30
2math.sqrt(abs(81))9
3math.ceil(3.54+4.6)8
4math.floor(3.5 + 4.6)9
5.

Write a Python code to find the L.C.M. of two numbers?

Answer»

Method I using functions:

def lcm (x, y):

if x > y:

greater = x

else:

greater = y while (true):

if ((greater % x = = 0) and (greater % y = = 0)):

lcm = greater break

greater + = 1

return lcm

num 1 = int (input(“Enter first number : “))

num 2 = int (input(“Enter second number : “))

print (“The L.C.M of” , numl, “and” , num, “is” , lcm(num1, num2))

Method II

(without using functions)

a = int (input (“Enter the first number :”))

b = int (input (“Enter the second number :”))

if a > b:

mini = a

else:

min 1 = b

while(1):

if (min 1 % a = = 0 and mini 1 % b = = 0):

print (“LCM is:” , mini)

break

mini = min 1 + 1

Output:

Enter the first number: 15

Enter the second number: 20

LCM is: 60

6.

……. function is used to evaluate the input value.(a) Input(b) Valuate(c) Eval(d) Val

Answer»

Eval function is used to evaluate the input value.

7.

Find the output.d = 43 print(‘A =ord(d))(a) 67(b) 95(c) 97(d) 65

Answer»

Answer is (d) 65

8.

………. function returns the smallest integer greater than or equal to x(a) Sqrt(b) Flow(c) Floor(d) Cell

Answer»

Cell function returns the smallest integer greater than or equal to x

9.

How many formats are there for the format ( ) functions?(a) 12(b) 5(c) 3(d) 1

Answer»

There are 3 format ( ) functions

10.

………. function is used to evaluate the input value. (a) Input (b) Valuate(c) Eval(d) Val

Answer»

Eval function is used to evaluate the input value.

11.

Give the syntax for passing parameters in functions?

Answer»

Parameters or arguments can be passed to functions def function _ name (parameter (s) separated by comma):

12.

Explain recursive function with an example?

Answer»

Python recursive functions

When a function calls itself is known as recursion. Recursion works like loop but sometimes it makes more sense to use recursion than loop. You can convert any loop to recursion.

A recursive function calls itself. Imagine a process would iterate indefinitely if not stopped by some condition! Such a process is known as infinite iteration. The condition that is applied in any recursive function is known as base condition. A base condition is must in every recursive function otherwise it will continue to execute like an infinite loop.

Working Principle:

1. Recursive function is called by some external code.

2. If the base condition is met then the program gives meaningful output and exits.

3. Otherwise, function does some required processing and then calls itself to continue recursion. Here is an example of recursive function used to calculate factorial.

Example:

def fact (n):

if n = = 0:

return 1

else:

return n * fact (n – 1)

print (fact (0))

print (fact (5))

Output:

1

120

13.

What is base condition in recursive function?

Answer»

The condition that is applied in any recursive function is known as base condition. A base condition is must in every recursive function otherwise it will continue to execute like an infinite loop.

14.

How recursive function works?

Answer»

1. Recursive function is called by some external code.

2. If the base condition is met then the program gives meaningful output and exits.

3. Otherwise, function does some required processing and then calls itself to continue recursion

15.

How to set the limit for recursive function? Give an example?

Answer»

Python also allows you to change the limit using 

sys.setrecursionlimit (limit value).

Example:

import sys

sys.setrecursionlimit(3000)

def fact (n):

if n = = 0:

return 1

else:

return n * fact (n – 1)

print (fact (2000))

16.

Find true statement(a) Recursive function call itself(b) Recursive function have to be called externally

Answer»

(a) Recursive function call itself