

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.
951. |
What does sys.argv[1:] mean? |
Answer» A list of the command-line arguments. |
|
952. |
Write a program that takes a number and calculate and display the log, square, sin and cosine of it. |
Answer» # Program to display the various values of a number import math > > > number = input (“Enter the number :”) > > > print “Number is”, number > > > print “Log value of number is” math.log (number) > > > print “Square of number is”, math.pow (number, 2) > > > print “Sin value of number is”, math.sin (number) > > > print “Cosine value of number is”, math.cos (number) |
|
953. |
Define a function ‘Subtract Number (x, y)’ which takes in two numbers and returns the different of the two. |
Answer» # Python function which returns the difference of two numbers > > > a = input (“Enter the first number :”) > > > b = input (“Enter the second number :”) def Subtract Number (a, b): > > > print “Subtraction = %d – %d” % (a, b) > > > return a – b |
|
954. |
How do you make a higher order function in Python ? |
Answer» ● A high order function accepts one or more functions as input and returns a new function. Sometimes it is required to use function as data. ● To make high order function, one need the import functools module. ● The functools.partial() function is used often for high order function. |
|
955. |
What value will be return by “choice(seq)” ? |
Answer» A random item from a list, tuple, or string. |
|
956. |
What value will be return by “random()” ? |
Answer» A random float r, such that 0 is less than or equal to r and r is less than 1. |
|
957. |
What does the len() function do? |
Answer» It gets the length of the string that you pass to it then returns it as a number. Play with it. |
|
958. |
Find the error(s) in the following code and correct them:1. def describe intelligent life form ():2. height = raw_input (“Enter the height”)3. raw_input (“Is it correct ?”)4. weight = raw_input (“Enter the weight”)5. favorite-game = raw_input (“Enter favorite game”)6. print “your height”, height, ‘and weight’, weight7. print “and your favorite game is”, favorite- game, ‘.’ |
Answer» Here, function name contains spaces. But function name should be a valid Python identifier with no spaces in between. And here, no variable is defined to obtain value being input. Lines 4 and 6 are badly indented; being part of same function, those should be at the same indentation level as that of lines 2, 3, 5 and 7. And also, variable favourite-game is an invalid identifier as it contains a hyphen, but it should have been an underscore. |
|
959. |
Write a program to read the user name using raw_input() and display back on the screen using print() |
Answer» #!/usr/bin/python name=raw_input(‘Enter your name :’) print (“Hi %s, Let us be friends!” % name); |
|
960. |
Write a program to swap two numbers. |
Answer» a = 5 b = 9 def swap(c,d): return d,c swap(a,b) |
|
961. |
Write any two math.h library functions. |
Answer» sqrt() and pow() are two libarary functions of math.h. |
|
962. |
Write any two library functions of stdlib.h. |
Answer» Two functions of stdlib.h are atoi() and itoa(). |
|
963. |
Write any two library functions of string.h. |
Answer» Two functions of string.h are strlen() and strcpy() |
|
964. |
Write any two functions of ctype.h? |
Answer» Two functions of ctype.h are isalpha() and isdigit(). |
|
965. |
Mention the function which can convert upper case letters to lower case letters. |
Answer» The function tolower() converts an uppercase letter to a lower case letter. |
|
966. |
Give the name of ctype.h member function which can convert lower case letter to uppercase letters. |
Answer» The function toupper() converts lower case letters to upper case letters. |
|
967. |
Define tan(x) function in python. |
Answer» Tan(x) function return the tangent of x radians. |
|
968. |
What is the output of ispunct (‘@’)? |
Answer» The output of ispunct (‘@’) is 1 means it is TRUE. |
|
969. |
What is the output of toascii (‘A’)? |
Answer» The output of toascii (‘A’) is 65. |
|
970. |
Why we use degrees(x) ? |
Answer» It converts angle x from radians to degrees. |
|
971. |
What is the output of isdigit (‘3’)? |
Answer» The output of isdigit (‘3’) is 1 means it is TRUE. |
|
972. |
Considering the following function definition;The expected, desired output is 5! = 120 What will be the actual output of the program? It is not the same as above, why? What modification are required in the program to get the desired output. |
Answer» The output is 0! = 120 Because the address of variable ‘a’ is given to the variable ‘n’ of the function fact(call by reference method). So the function changes its value (i.e. n- -) to 0. Hence the result. To get the desired result call the function as call by value method in this method the copy of the value of the variable ‘a’ is given to the function. So the actual value of ‘a’ will not changed. So instead of int fact(int &n) just write int fact(int n), i.e., no need of & symbol. |
|
973. |
What is the use of isalnum() function? |
Answer» It returns True if the argument is a digit from 0 through 9 or an alphabetic character (either uppercase or lowercase) otherwise returns False. |
|
974. |
What is the function of cos()? |
Answer» cos() is a mathematical function that returns the cosine value for the given radians. |
|
975. |
What is the output of sqrt(25)? |
Answer» The output of sqrt(25) is 5. |
|
976. |
What is the use of expO function? |
Answer» exp() is a mathematical function that returns the natural logarithm base “e” raised to the argument’s power. |
|
977. |
What will be the output of the following codeclass c (object): ….def_init_(self):self.x = 1 C = C() print C.X print C.X print C.X print C.X |
Answer» All the outputs will be 1, since the value of the objects attribute (X) is never changed. 1 1 1 1 X is now a part of the public members of the class C. Thus it can be accessed directly |
|
978. |
Explain floor(x) in Python with example. |
Answer» The method floor() returns floor of x – the largest integer not greater than x. Syntax: Following is the syntax for floor() method import math math.floor(x) Note: This function is not accessible directly so we need to import math module and then we need to call this function using math static object. Parameters : x — This is a numeric expression. Return Value: This method returns largest integer not greater than x. Example: The following example shows the usage of floor() method. # !/usr/bin/python import math # This will import math module print “math.floor(-45.17): “, math.floor(-45.17) print “math.floor(100.12): “, math.floor(100.12) print “math.floor(100.72): “, math.floor(100.72) print “math.floor(119L):”, math.floor(119L) print “math.floor(math.pi):”, math.floor(math.pi) This will produce the following result: math.floor(-45.17) :-46.0 math.floor(100.12):100.0 math.floor(100.72): 100.0 math.floor(119L): 119.0 math.floor(math.pi): 3.0 |
|
979. |
What type of errors does the exception type NameError correspond to? |
Answer» A variable that is not initialized (defined), perhaps a variable/function that is misspelled. |
|
980. |
What is the output of cell(25.456) function? |
Answer» The cell() function gives the smallest integer not less than the given value. |
|
981. |
Why we use ceil(x) function? |
Answer» It returns the ceiling of x as a float, the smallest integer value greater than or equal to x. |
|
982. |
Why we use floor(x) function? |
Answer» It returns the floor of x as a float, the largest integer value less than or equal to x. |
|
983. |
What value will be return by cos(x)? |
Answer» Returns the cosine of x radians. |
|
984. |
What value will be return by log10(x) ? |
Answer» Returns the base-10 logarithm of x. This is usually more accurate than log(x,10). |
|
985. |
What value will be return by sqrt(x)? |
Answer» Returns the square root of x. |
|
986. |
What is the output of the following code? print type([l,2]) |
Answer» print type([l,2]) |
|
987. |
What should the below code print? print type(1J |
Answer» < type’complex’> |
|
988. |
Find the domain of the range of each of the following real functions: `f(x)=(3x-2)/(x+2)` |
Answer» Correct Answer - dom `(f)=R-{-2}," range "(f)=R-{3}` `f(x)=(3x-2)/(x+2)` not defined when x=-2. So, dom `(f)=R-{-2}`. Let y=f(x). Then, `y=(3 x-2)/(x+2)impliesxy+2y=3x-2implies3x-xy=2y+2` `impliesx(3-y)=2y+2impliesx=(2y+2)/(3-y)." "....(i)` It follows from (i) that x is not defined when y=3. `:." range "(f)=R-{3}`. |
|
989. |
Find the domain of the range of each of the following real functions: `f(x)=(x^(2)-16)/(x-4)` |
Answer» Correct Answer - dom `(f)=R-{4}," range "(f)=R-{8}` `f(x)=(x^(2)-16)/(x-4)` is not defined when x=4. So, dom `(f)=R-{4}`. Let y=f(x). Then, `y=(x^(2)-16)/(x-4)=(x+4)," when "xne5` `impliesyne(4+4)impliesyne8." So, range "(f)=R-{8}`. |
|
990. |
Find the domain of the range of each of the following real functions: `f(x)=(x-3)/(2-x)` |
Answer» Correct Answer - dom `(f)=R-{2}," range "(f)=R-{-1}` `f(x)=(x-3)/(2-x)` is not defined when x=2. So, dom `(f)=R-{2}`. Let y=f(x). Then, `y=(x-3)/(2-x)implies2y-xy=x-3impliesxy+x=2y+3` `impliesx(y+1)=2y+3impliesx=(2y+3)/(y+1)`. `:.` x is not defined when y=-1. So, range `(f)=R-{-1}` |
|
991. |
Find the domain of the range of each of the following real functions: `f(x)=(1)/(x-5)` |
Answer» Correct Answer - dom `(f)=R-{0}," range "(f)=R-{0}` `f(x)=(1)/((x-5))` is not defined when x=5. So, dom `(f)=R-{5}`. Let y=f(x). Then, `y=(1)/((x-5))impliesx-5=(1)/(y)impliesx=((1)/(y)+5)`. `:.` x is not defined when y=0. So, range `(f)=R-{0}`. |
|
992. |
Find the domain of the range of each of the following real functions: `f(x)=1-|x-2|` |
Answer» Correct Answer - dom `(f)=R," range "(f)=(-oo,1]` `f(x)=1-|x-2|` is defined for all `x""inR`. So, dom (f)=R. Now, `0le|x-2|ltooimplies|x-2|ge0and|x-2|ltoo` `implies-|x-2|le0and-|x-2|gt-oo` `implies1-|x-2|le0and-|x-2|gt-oo` `implies-oolt1-|x-2|le1impliesf(x)in(-oo,1]`. `:."range "(f)=(-oo,1]`. |
|
993. |
Find the domain of the range of each of the following real functions: `f(x)=sqrt(3x-5)` |
Answer» Correct Answer - dom `(f)=[(5)/(3),oo)," range "(f)=R-[0,oo)` `f(x)=sqrt(3x-5)` is defined only when `3x-5ge` i.e., when `3x-5ge0`, i.e., when `xge(5)/(3)`. `:."dom "(f)={(5)/(3),oo}`. `xge(5)/(3)impliesf(x)ge0" range "(f)=R-[0,oo)`. |
|
994. |
Find the domain of the range of each of the following real functions: `f(x)=(1)/(sqrt(2x-3))` |
Answer» Correct Answer - dom `(f)=R-(-oo,(3)/(2))," range "(f)=R-{0}` `f(x)=(1)/(sqrt(2x-3))` is not defined when `2x-3le0` i.e., when `xle(3)/(2)`. `:."dom "(f)=R-(-oo,(3)/(2)]`. Let y=f(x). Then, `y=(1)/(sqrt(2x-3))impliesy^(2)=(1)/((2x-3))implies(2x-3)=(1)/(y^(2))impliesx=(1)/(2)((1)/(y^(2))+3)`. `:.` x is not defined when y=0. So, range `(f)=R-{0}`. |
|
995. |
Find the domain of the range of each of the following real functions: `f(x)=(x^(2)-9)/(x-3)` |
Answer» Correct Answer - dom `(f)=R-{3}," range "(f)=R-{6}` `f(x)=(x^(2)-9)/(x-3)impliesy=x+3`, when `xne3`. `:.dom(f)=R-{3}`. Let y=f(x). Then, `y=(x^(2)-9)/(x-3)impliesy=x+3`, when `xne3` `impliesyne3+3impliesyne6`. `:."range "(f)=R-{6}`. |
|
996. |
Find the domain of the range of each of the following real functions: `f(x)=(1)/(x)` |
Answer» Correct Answer - dom `(f)=R-{0}," range "(f)=R-{0}` `f(x)=(1)/(x)` is not difined when x=0. So, dom `(f)=R-{0}`. Let y=f(x). Then, `y=(1)/(x)impliesx=(1)/(y)`. `:.` x is defined when y=0. So, range `(f)=R-{0}`. |
|
997. |
If `y=f(x)=(3x+1)/(5x-3)`, prove that x=f(y). |
Answer» `f(y)=(3y+1)/(5y-3)=(3((3x+1)/(5x-3))+1)/(5((3x+1)/(5x-3))-3)=(9x+3+5x-3)/(15x+5-15x+9)=(14x)/(14)=x`. | |
998. |
Find the domain and the range of the function, `f(x)=(x^(2)-25)/(x-5)`. |
Answer» We have, `f(x)=(x^(2)-25)/(x-5)` Clearly, f(x) is defined for all real values of x for which `x-5ne0,i.e.,xne5`. `:."dom "(f)=R-{5}`. Let y=f(x). Then, `y=(x^(2)-25)/(x-5)impliesy=x+5,"when "x-5ne0` `impliesy=x+5,"when "xne5` `impliesyne5+5impliesyne10`. Then, y can be assigned any real value except 10. `:."range "(f)=R-{10}`. Hence, dom `(f)=R-{5}"and range "(f)=R-{10}`. |
|
999. |
Find the domain and the range of the function, `f(x)=(x-2)/(x-3)`. |
Answer» We have, `f(x)=(x-2)/(x-3)` Clearly, f(x) is defined for all real values of x for which `x-3ne0`, i.e., `xne3`. `:."dom "(f)=R-{3}`. Let y=f(x). Then, `y=(x-2)/(x-3)impliesxy-3y=x-2` `impliesx(y-1)=3y-2` `impliesx=(3y-2)/(y-1)." "....(i)` It follows from (i) that x assumes real values for all y except that for which y-1=0, i.e., y=1. `:."range "(f)=R-{1}`. Hence, dom `(f)=R-{3}"and range "(f)=R-{1}`. |
|
1000. |
If log3 [log2 (log3 x)] = 1, show that x = 6561. |
Answer» log3 [log2 (log3 x)] = 1 ∴ log2 (log3 x) = 31 ∴ log3 x = 23 ∴ log3 x = 8 ∴ x = 38 ∴ x = 6561 |
|