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.
| 751. |
Find the domain of the following functions.f(x) = \(\sqrt {x-3}+ \frac{1}{log (5-x)}\)fx = √x-3 + 1/log(5-x) |
|
Answer» f(x) = \(\sqrt{x-3} + \frac {1}{log(5-x)}\) For f to be defined, x – 3 ≥ 0, 5 – x > 0 and 5 – x ≠ 1 x ≥ 3, x < 5 and x ≠ 4 ∴ Domain of f = [3, 4) ∪ (4, 5) |
|
| 752. |
Without using log tables, prove that 2/5 < log10 3 < 1/2. |
|
Answer» We have to prove that, 2/5 < log10 3 < 1/2 i.e., to prove that 2/5 < log10 3 and log10 3< 1/2 i.e., to prove that 2 < 5 log10 3 and 2 log10 3 < 1 i.e., to prove that 2 log10 10 < 5 log10 3 and 2 log10 10 …… [∵ loga a = 1] i.e., to prove that log10 102 < log10 35 and log10 32 < log10 10 i.e., to prove that 102 < 35 and 32 < 10 i.e., to prove that 100 < 243 and 9 < 10 which is true ∴ 2/5 < log10 3 < 1/2 |
|
| 753. |
Find composite of f and g:f = {(1, 3), (2, 4), (3, 5), (4, 6)} g = {(3, 6), (4, 8), (5, 10), (6, 12)} |
|
Answer» f = {(1, 3), (2, 4), (3, 5), (4, 6)} g = {(3, 6), (4, 8), (5, 10), (6, 12)} ∴ f(1) = 3, g(3) = 6 f(2) = 4, g(4) = 8 f(3) = 5, g(5)=10 f(4) = 6, g(6) = 12 gof) (x) = g (f(x)) (gof)(1) = g(f(1)) = g(3) = 6 (gof)(2) – g(f(2)) = g(4) = 8 (gof)(3) = g(f(3)) = g(5) = 10 (gof)(4) = g(f(4)) = g(6) = 12 ∴ gof = {(1, 6), (2, 8), (3, 10), (4, 12)} |
|
| 754. |
If y = f(x) = \(\frac{ax-b}{bx-a}\), show that x = f(y). |
|
Answer» Given, y = f(x) = (ax-b)/(bx-a) ⇒ f(y) = \(\frac{ay-b}{by-a}\) We need to prove that x = f(y). We have, y = \(\frac{ax-b}{bx-a}\) ⇒ y(bx – a) = ax – b ⇒ bxy – ay = ax – b ⇒ bxy – ax = ay – b ⇒ x(by – a) = ay – b ⇒ x = \(\frac{ay-b}{by-a}\) = f(y) ∴ x = f(y) Thus, x = f(y). |
|
| 755. |
If f(x) = ax + bx + 2 and f(1) = 3, f(4) = 42,find a and b. |
|
Answer» f(x) = ax2 + bx + 2 f(1) = 3 ∴ a(1)2 + b(1) + 2 = 3 ∴ a + b = 1 ….(i) f(4) = 42 ∴ a(4)2 + b(4) + 2 = 42 ∴ 16a2 + 4b = 40 Dividing by 4, we get 4a + b = 10 …..(ii) Solving (i) and (ii), we get a = 3, b = -2 |
|
| 756. |
If f is a real function defined by `f(x)=(x-1)/(x+1)`, then prove that `f(2x)=(3f(x)+1)/(f(x)+3)` |
|
Answer» We have, `f(x)=(x-1)/(x+1)`. `:.(3f(x)+1)/(f(x)+3)=(3((x-1)/(x+1))+1)/(((x-1))/((x+1))+3)` `=((3x-3)+(x+1))/((x+1))xx((x+1))/((x-1)+(3x+3))=(2x-1)/(2x+1)=f(2x)`. Hence, `f(2x)=(3f(x)+1)/(f(x)+3)`. |
|
| 757. |
if y = f(X) = `(ax-b)/(bx-a)` show that x = f(y) |
|
Answer» We have, `y=f(x)=(ax-b)/(bx-a)`. `:.f(y)=f{f(x)}=f((ax-b)/(ax-))={{a((ax-b)/(bx-a))-b}}/{{b((ax-b)/(bx-a))-a}}` `={{(a^(2)x-ab)-(b^(2)x-ab)}}/((bx-a))xx((bx-a))/{{(abx-b^(2))-(abx-a^(2))}}` `=((a^(2)x-b^(2)x))/((a^(2)-b^(2)))=((a^(2)-b^(2))x)/((a^(2)-b^(2)))=x`. Hence, x=f(y). |
|
| 758. |
Let `f={(-1,-3),(0,-1),(1,1),(2,3)}` be a function, described by the formula, `f(x)=alphax+beta`. Then, find the valves of `alphaandbeta`. Also, find the formula. |
|
Answer» Here `f(x)=alphax+beta" "....(i)` Also, `f(-1)=-3,f(0)=-1,f(1)=1andf(2)=3." "["given"]` Putting `x=-1andf(-1)=-3` in (i), we get `-alpha+beta=-3impliesalpha-beta=3" "....(ii)` Putting `x=0andf(0)=-1` (i), we get `alphaxx0+beta=-1impliesbeta=-1" "....(iii)` Putting `beta=-1` from (iii), in (ii), we get `alpha=2`. `:.alpha=2andbeta=-1`. Hence, `f(x)=2x-1` is the required formula. |
|
| 759. |
Find the domain of each of the following real fuctions: (i) `f(x)=sqrt(x-3)` (ii) `g(x)=sqrt(4-x^(2))` (iii) `h(x)=(1)/(sqrt(1-x))`. |
|
Answer» (i) We have, `f(x)=sqrt(x-3)`. Clearly, f(x) is defined for all real values of x for which `x-3ge0,i.e.,xge3`. `:."dom "(f)=[3,oo)`. (ii) We have, `g(x) =sqrt(4-x^(2))` Clearly, g(x) is defined for all real values of x for which `(4-x^(2))ge0` But, `(4-x^(2))ge0implies-(4-x^(2))le0` `impliesx^(2)-4le0implies(x+2)(x-2)le0` `implies-2lexle2impliesx""in[-2,2]`. `:."dom "(g)=[-2,2]`. (iii) We have, `h(x)=(1)/(sqrt(1-x))` Clearly, h(x) is defined for all real values of x for which `(1-x)gt0`. But, `1-xgt0implies1gtximplieslt1impliesx""in(-oo,1)`. `:."dom "(h)=(-oo,1)`. |
|
| 760. |
Find the domain and the range of the real function, `f(x)=(1)/(sqrt(x+[x]))`. |
|
Answer» We have, `f(x)=(1)/(sqrt(x+[x]))` We know that `{{:(x+[x]gt0"for all "xgt0),(x+[x]=0",when "x=0),(x+[x]lt0"for all "xlt0):}` `:.f(x)=(1)/(sqrt(x+[x]))` is defined only when `x+[x]gt0` and this happens only when `xgt0`. `:."dom "(f)=(0,oo)`. Let y=f(x). Then, `y=(1)/(sqrt(x+[x]))impliessqrt(x+[x])=(1)/(y)." "....(i)` Now, `xgt0impliesx+[x]gt0impliessqrtx+[x]gt0implies(1)/(y)gt0impliesygt0`. `:."range "(f)=(0,oo)`. Hence, dom `(f)=(0,oo)"andrange "(f)=(0,oo)`. |
|
| 761. |
Find the domain and range of the real function `f(x) = sqrt(9 -x^(2))` |
|
Answer» If its clear that f(x) `= sqrt(9-x^(2))` is not defined when `(9-x^(2)) lt 0, i.e.,` When `x^(2) gt 9 , i.e., " when " x gt 3 " or " x lt -3` `:. " don " (f) ={ x in R : -3 le x le 3}` Also `y= sqrt(9 - x^(2)) rArr y^(2) = (9 -x^(2))` ` rArr x= sqrt(9 -y^(2))` Clearly x is not defined when `(9-y^(2)) lt 0` But `(9-y^(2)) lt 0 rArr y^(2) gt 9` `rArr y gt 3 " or " y lt -3` `:.` range `(f) ={ y in R : - 3 le y le 3}` |
|
| 762. |
Find the domain of the real-valued function: `f(x)=(x^(2)-x+1)/(x^(2)-5x+4)`. |
|
Answer» We have, `f(x)=(x^(2)-x+1)/(x^(2)-5x+4)` Clearly, f(x) is defined for all real values of x except those at which `x^(2)-5x+4=0` But, `x^(2)-5x+4=0implies(x -1)(x-4)=0impliesx=1orx=4`. `:."dom "(f)=R-{1,4}`. |
|
| 763. |
Let `f:RtoR:f(x)=x^(2)+3`. Find the pre-images of each of the following under f: (i) 19 (ii) 28 (iii) 2 |
|
Answer» Given: `f(x)=x^(2)+3`. (i) Let x be pre-image of 19. Then, `f(x)-19impliesx^(2)+3=19impliesx^(2)=16impliesx=pm4`. `:.` 4 and -4 are the pre-images of 19. (ii) Let x be the pre-image of 28. Then, `f(x)=28impliesx^(2)+3=28impliesx^(2)=25impliesx=pm5`. `:.` 5 and -5 are the pre-images of 28. (iii) Let x be the pre-images of 2. Then, `f(x)=2impliesx^(2)+3=2impliesx^(2)=-1`. But, no real value of x satisfies the equation, `x^(2)=-1`. `:.` 2 does not have any pre-image under f. |
|
| 764. |
Find the domain and the range of the real function, `f(x)=(x-3)/(x-5)`. |
|
Answer» We have, `f(x)=(x-3)/(x-5)`. Clearly, f(x) is defined for all real values of x except that at which `x-5=0,i.e.,x=5`. `:."dom"(f)=R-{5}` Let `y=f(x)`. Then, `y=(x-3)/(x-5)impliesxy-5y=x-3` `impliesx(y-1)=5y-3impliesx=(5y-3)/(y-1)." "....(i)` It is clear from (i) that x is not defined when y-1=0, i.e., when y=1. `:."range"(f)=R-{1}`. Hence, dom `(f)=R-{5}" and range "(f)=R-{1}`. |
|
| 765. |
Let `A=" "{1,2,3,4,5," "6," "7," "8," "9," "10}`and `B" "=" "{" "2,3,5,7" "}dot`Find `A nnB`and hence show that `A nnB" "=" "Bdot` |
|
Answer» Here `f:[0,oo)toR:f(x)=sqrtxandg:[0,oo)toR:g(x)=x`. `:."dom "(f)=[0,oo)" and dom "(g)=[0,oo)` So, dom `(f)nn" dom "(g)=[0,oo)nn[0,oo)=[0,oo)`. (i) `(f+g):[0,oo)toR` is given by `(f+g)(x)=f(x)+g(x)=(sqrtx+x)`. (ii) `(f-g):[0,oo)toR` is given by `(f-g)(x)=f(x)-g(x)=(sqrtx-x)`. (iii) `(fg):[0,oo)toR` is given by `(fg)(x)=f(x).g(x)=(sqrtx""xxx)=x^(3//2)` (iv) `{x:g(x)=0}={0}`. `:."dom "((f)/(g))=" dom "(f)nn"dom "(g)-{x:g(x)=0}` `=[0,oo)nn[0,oo)-{0}=(0 ,oo)`. So, `(f)/(g):(0,oo)toR` is given by `((f)/(g))(x)=(f(x))/(g(x))=(sqrtx)/(x)=(1)/(sqrtx),xne0`. |
|
| 766. |
Let f and g be real functions, defined by `f(x)=(1)/((x+4))andg(x)=(x+4)^(3)`. Find (i) `(f+g)(x)` (ii) `(f-g)(x)` (iii) `(fg)(x)` (iv) `((f)/(g))(x)` (v) `((1)/(f))(x)` |
|
Answer» Clearly, `f(x)=(1)/((x+4))` is defined for all real values of x except that at which `x+4=0,i.e.,x=-4`. `:."dom "(f)=R-{-4}`. And, `g(x)=(x+4)^(3)` is defined for all `x""inR`. So, dom (g)=R. `:."dom "(f)nn"dom "(g)=R-{-4}nnR-{-4}`. (i) `(f+g):R-{-4}toR` is given by `(f+g)(x)=f(x)+g(x)=(1)/((x+4))+(x+4)^(4)=(1+(x+4)^(4))/((x+4))` (ii) `(f-g):R-{-4}toR` is given by `(f-g)(x)=f(x)-g(x)=(1)/((x+4))xx(x+4)^(3)=(1-(x+4)^(4))/((x+4))` (iii) `(fg):R-{-4}toR` is given by `(fg)(x)=f(x).g(x)=(1)/((x+4))xx(x+4)^(3)=(x+4)^(2)`. (iv) `{x:g(x)=0}={x:(x+4)^(3)=0}={x:x+4=0}={-4}`. `:."dom "((f)/(g))="dom "(f)nn"dom "(g)-{x:g(x)=0}=R-{-4}`. `((f)/(g))(x )=(f(x))/(g(x))=((1)/((x+4)))/((x+4))=(1)/((x+4)^(4)),xne-4` (v) Clearly, `f(x)ne0" for any "x""inR-{-4}`. `:.(1)/(f):R-{-4}toR` is given by `((1)/(f))(x)=(1)/(f(x))=(1)/((1)/((x+4)))=(x+4)`. |
|
| 767. |
Let `f:ZtoZ:f(x)=x^(2)andg:ZtoZ:g(x)=|x|^(2)" for all "x""inZ`. Show that f=g. |
|
Answer» We have dom (f)= dom (g) =Z and co-domain of f=co-domain of g =Z. Also, for all `x""inZ`, we have `f(x)=x^(2)andg(x)=|x|^(2)=x^(2)` `:.f(x)=g(x)" for all "x""inZ.` Hence, f=g. |
|
| 768. |
Two functions `f:R to R and g:Rto R` are defined as follows: `f(x)={{:(,0,x in Q),(,1,x ne Q):},g(x)={{:(,-1,x in Q),(,0,x in Q):}` Then, fof (e)+fog`(pi)`A. `-1`B. 0C. 1D. 2 |
|
Answer» Correct Answer - A We have `gof(e)+fog(pi)=g(f(e))+f(g(pi)) =g(1)+f(0)=-1+0=-1` |
|
| 769. |
The relation f is defined by `f(x)={x^2,0lt=xlt=3 3x ,3lt=xlt=10`The relating g is defined by `g(x)={x^2,0lt=xlt=3 3x ,2lt=xlt=10`Show that f is a function and g is not a function. |
|
Answer» We have, dom `(f)=[0,10]subR`. Now, `f(2)=2^(2)=4` and also, `f(2)=(3xx2)=6`. As such a single element, namely 2 has two distinct images, namely 4 and 6. `:.` f is not a function. |
|
| 770. |
f, g and h are three functions defined from R to R as follows: (i) `f(x)=x^(2)` (ii) `g(x)=x^(2)+1` (iii) `h(x)=sinx` Then, find the range of each function. |
|
Answer» (i) Clearly, `f(x)=x^(2)ge0" for all "x""inR`. (ii) `f(x)=x^(2)+1ge1" for all "x""inR`. `sinx""in[-1,1]`. |
|
| 771. |
The function `F(x)=(9x)/(5)+32` is the formula to convent `x^(@)C` to Fahrenheit units. Find (i) F(0), (ii) F(-10), (iii) the value of x when f(x)=212. Interpret the result in each case. |
|
Answer» (i) `f(0)={(9xx0)/(5)+32}=32implies0^(@)C=32^(@)F`. (ii) `f(10)={(9xx(-10))/(5)+32}=14implies(-10)^(@)C=14^(@)F` (iii) `F(x)=212implies(9x)/(5)+32=212impliesx=100implies212^(@)F=100^(@)C`. |
|
| 772. |
Let `f:RtoR:f(x)=x^(2)+1`. Find (i) `f^(-1){10}` (ii) `f^(-1){-3}` |
|
Answer» (i) `x^(2)+1=10impliesx^(2)=9impliesx=pm3`. (ii) `x^(2)+1=-3impliesx^(3)=-4` and there is no real number whose square is -4. |
|
| 773. |
If `f:RtoR` is given by `f(x)=3x-5` then `f^-1(x)`A. is given by `(1)/(3x-5)`B. is given by `(x+5)/(3)`C. does not exist because f is not one-oneD. doses not exist because f is not onto |
|
Answer» Correct Answer - B Given, `f(x)=3x-5 " " ` [given] Let `y=f(x)=3x-5 rArr y+5=3x` `rArr x=(y+5)/(3)` `f^(-1)(y)=(y+5)/(3)` `rArr f^(-1)(x)=(x+5)/(3)` |
|
| 774. |
If `f`is a real function satisfying `f(x+1/x)=x^2+1/(x^2)`for all `x in R-{0}`, then write the expression for `f(x)`. |
|
Answer» Correct Answer - `f(x)=x^(2)-2,x""inR` `f(x+(1)/(x))=(x+(1)/(x))^(2)-2impliesf(x)=x^(2)-2impliesf(x)=x^(2)-2,x""inR` |
|
| 775. |
If `f(x)=sin^2x+sin^2(x+pi/3)+cosxcos(x+pi/3)` and `g(5/4)=1,`then `(gof)(x)`is ____________A. a polynomial of first degree in sin x and cos xB. a constant functionC. a polynomial of second degree in sin x and cos xD. none of these |
|
Answer» Correct Answer - B We have `f(x)=sin^(2)x+sin^(2)(x+(pi)/(3))+cos(x+(pi)/(3))cos x` `f(x)=(1)/(2){1-cos 2x+1-cos(2x+(2pi)/(3))+cos(2x+(pi)/(3))+"cos"(pi)/(3)}` `f(x)=(1)/(2)[(5)/(2)-{cos2x+cos(2x+(2pi)/(3)p)}+cos(2x+(pi)/(3))]` `Rightarrow f(x)=(1)/(2)[(5)/(2)-2cos(2x+(pi)/(3))"cos" (pi)/(3)+cos(2x+(pi)/(3))]` `f(x)=(5)/(4)"for all "x in R` `therefore "g of "(x)=g (f(x))=g((5)/(4))=1"for all x"` Hence, g of (x) is a constant functions. |
|
| 776. |
Let f : R → R : f(x) (2x - 3) and \(g:R→R:g(x)=\frac{1}{2}(x+3)\). Show that (f o g) = IR = (g o f). |
|
Answer» To prove: (f o g) = IR = (g o f). Formula used: (i) f o g = f(g(x)) (ii) g o f = g(f(x)) Given: (i) f : R → R : f(x) = (2x - 3) (ii) \(g:R→R:g(x)=\frac{1}{2}(x+3)\) Solution: We have, f o g = f(g(x)) \(=f(\frac{1}{2}(x+3))\) \(=[2(\frac{1}{2}(x+3))-3]\) = x + 3 – 3 = x = IR g o f = g(f(x)) = g(2x - 3) \(=\frac{1}{2}(2x-3+3)\) \(=\frac{1}{2}(2x)\) = x = IR Clearly we can see that (f o g) = IR = (g o f) = x Hence Proved. |
|
| 777. |
A function `f: IR ->IR`, where `IR`, is the set of real numbers, is defined by `f(x) = (ax^2 + 6x - 8)/(a+6x-8x^2)` Find the interval of values of a for which is onto. Is the functions one-to-one for `a =3 ?` Justify your answer. |
|
Answer» Correct Answer - `2 le alpha le 14,` No Let, `y=(alpha x^(2)+6x-8)/(alpha +6x-8x^(2))` `rArr alpha y + 6xy-8x^(2)y=alpha x^(2)+6x-8` `rArr -alpha x^(2)-8x^(2)y+6xy-6x+alpha y +8 =0` `rArr alpha x^(2)+8x^(2)y-6xy+6x-alpha y-8=0` `rArr x^(2)(alpha +8y)+6x(1-y)-(8+alpha y)=0` Since, x is real. `rArr B^(2)-4AC ge 0` `rArr 36(1-y)^(2)+4(alpha +8y)(8+alpha y) ge 0` `rArr 9(1-2y+y^(2))+[8alpha +(64 +alpha^(2))y+8alpha y^(2)] ge 0` `rArr y^(2)(9+8alpha)+y(46+alpha^(2))+9+8alpha ge 0 " ...(i)" ` `rArr A ge 0, D le 0, rArr 9+8alpha gt 0` `and (46+alpha^(2))^(2)-4(9+8alpha)^(2) le 0` `rArr alpha gt 9//8` ` and [46 + alpha^(2) -2(9+8alpha)][46 +alpha^(2)+2(9+8alpha)] le 0` `rArr a gt -9//8` `and (alpha^(2)-16alpha+28)(alpha^(2)+16alpha+64) le 0` `rArr alpha gt -9//8` `and [(alpha -2)(alpha-14)](alpha-8)^(2) le 0` `rArr alpha gt -9//8` `and (alpha -2)(alpha -14) le 0 " " [because (alpha +8)^(2) ge 0]` `rArr alpha gt -9//8` `and 2 le alpha le 14` `rArr 2 le alpha le 14` Thus, `f(x)=(alpha x^(2)+6x-8)/(alpha+6x-8x^(2))` will be onto, if `2 le alpha le 14` Again, when `alpha =3` `f(x)=(3x^(2)+6x-8)/(3+6x-8x^(2))`, in this case `f(x)=0` `rArr 3x^2)+6x-8=0` `rArr x=(-6pm sqrt(36+96))/(6)=(-6pm sqrt(132))/(6)=(1)/(3)(-3pm sqrt(33))` This shows that `f[(1)/(3)(-3+ sqrt(33))]=f[(1)/(3)(-3- sqrt(33))]=0` Therefore, f is not one-to-one. |
|
| 778. |
If `y=f(x)=((x+2))/((x-1)),t h e n``x=f(y)`(b) `f(1)=3``y`increases with `xforx |
|
Answer» Correct Answer - A::D Given, `y=f(x)=(x+2)/(x-1)` `rArr yx-y=x+2 rArr x(y-1) = y+2` `rArr x=(y+2)/(y-1) rArr x=f(y)` Here, f(1) does not exist, so domain ` in R-{1}` `(dy)/(dx)=((x-1)*1-(x+2)*1)/((x-1)^(2))` `= -(3)/((x-1)^(2))` `rArr` f(x) is decreasing for all ` x in R -{1}.` Also, f is rational function of x. Hence, (a) and (d) are correct options. |
|
| 779. |
Describe sqrt(x) in Python with example. |
|
Answer» Description : The method sqrt( ) returns the square root of x for x > 0. Syntax: Following is the syntax for sqrt() method import math math.sqrt(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 square root of x for x > 0. Example: The following example shows the usage of sqrt() method. # !/usr/bin/python import math # This will import math module print “math.sqrt(100): “, math.sqrt(100) print “math.sqrt(7): “, math.sqrt(7) print “math.sqrt(math.pi): “, math.sqrt(math.pi) This will produce the following result: math.sqrt(100): 10.0 math.sqrt(7): 2.64575131106 math.sqrt(math.pi): 1.77245385091 |
|
| 780. |
A user-defined function can be called:(a) One time(b) Two times(c) Three times(d) More than three times |
|
Answer» Correct option is (d) More than three times |
|
| 781. |
Functions which are compiled into object modules are known as(a) Library functions(b) Recursive functions(c) User-defined functions(d) None of these |
|
Answer» Correct option is (a) Library functions |
|
| 782. |
Explain cos() in Python. |
|
Answer» Description: The method cos() returns the cosine of x radi Answer: Syntax : Following is the syntax for cos() method cos(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 must be a numeric value. Return Value : This method returns a numeric value between-1 and 1 which represents the cosine of the angle. Example: The following example shows the usage of cos() method # !/usr/bin/python import math print “cos(3):”, math.cos(3) print “cos(-3):”, math.cos(-3) print “cos(0):”, math.cos(0) print “cos(math.pi):”, math.cos(math.pi) print “cos(2*math.pi):”, math.cos(2*math.pi) This will produce the following result: cos(3) >0.9899924966 cos(-3) >0.9899924966 cos(0): 1.0 cos(math.pi) >1.0 |
|
| 783. |
Explain Return statement with example. |
|
Answer» Return Statement: The keyword return is used to terminate function and return a value to its caller. The return statement may also be used to exit a function without returning a value. The return statement may or may not include an expression. # include<stdio.h> Output: |
|
| 784. |
What will be the output of this program? a = 20.3 b = ‘Python’ c = ‘”Python”‘ d = 21 print isinstance(a, float), print isinstance(b, (str, int)), print isinstance(c, (str, str)), print isinstance(d, (float, str)) |
|
Answer» True |
|
| 785. |
What value will be return by exp(x) ? |
|
Answer» Returns e**x. |
|
| 786. |
Write a tic-tac-toe program in python. |
|
Answer» # tic-tac-toe program import random def drawboard (board): # This function is used to print the board print (‘ | | ‘) print (‘ ‘ + board [7] + ‘ j ‘ + board [8] + ‘ | ‘ + board [9]) print (‘| | ‘) print (‘ ‘) print (‘| | ‘) print (‘ ‘ + board [4] + ‘ | ‘ + board [5] + ‘ | ‘ + board [6]) print (‘| | ‘) print (‘ ‘) Print (‘ | | ‘) print (‘ ‘ + board [1] + ‘ | ‘ + board [2] + ‘ | ‘ + board [3]) print (‘| | ‘) def input player letter (): # This function is used to display the user typed letter Letter = ” while not (letter = = ‘X’ or letter = = ‘O’): print (‘Do you want to be X or O ?’) letter = input () .upper () if letter = ‘X’ return [‘X’, ‘O’] else: return [‘O’, ‘X’] def whogoesFirst (): # This function is used to randomly choose the player if randomrandint (0,1) = = 0 : return ‘Computer’ else: return ‘Player’ def Play Again (): # This function is used when player wants play again print (‘Do you want to play again ? (Yes or no)’) return input (), lower ().startswith (‘y’) def makeMove (board, letter, move): board[move] = letter def is Winner (bo, le): # This function returns true when plays has won return (60[7] = = le and 60[8] = = le and 60[9] = = le) or (60[4] = = le and 60[5] = = le and 60[6] = = le) or (60[1 ] = = le and 60[2] = = le and 60[3] = = le) or (60[7] = = le and 60[4] = = le and 60[1] = = le) or (60[8] = = le and 60[5] = = le and 60[2] = = le) or (60[9] = = le and 60[6] = = le and 60[3] = = le) or (60[7] = = le and 60[5] = = le and 60[3] = = le) or (60[9] = = le and 60[5] = = le and 60[1] = = le) or def getBoardcopy(board): # This function make a duplicate of the board dupeBoard = [ ] for i in board : dupeBoard.append(i) return depeBoard def isSpaceFree (board, move): # This function returns Ttue if the passed move is free return boardfmove] = = ‘ ‘ def getPlayerMove(board): # This function is used to take player’s move move = ‘ ‘ while move not in’12345678 9’.split () or not is spaceFree (board, int(move)): print (‘What is your next move ? (1-9)’) move = input () return int(move) defchooseRandomMoveFromList(board, movelist): # This function returns a valid move from the passed list possible Moves = [ ] for i in moveList: if is SpaceFree (board, i): possibleMOves.append(i) if len(possibleMoves)! = 0 : return random.choice (possibleMoves) else: return – None defgetComputerMove(board, computerletter): # This function returns the computer’s letter if computer letter = = ‘X’: player letter = ‘O’ else: player letter = ‘X’ for i in range (1,10): copy = getBoardCopy (board) if isSpaceFree (copy, i): makeMove (copy, computerletter, i) if is Winner (copy, computerletter): return i for i in range (1,10): copy = getBoard Copy (board) if isSpaceFree (copy, i): makeMove (copy, player letter, i) if is Winner (copy, player letter): return i move=chooseRandomMoveFromList (board, [1, 3, 7, 9]) if move ! = None : return move if isSpaceFree (board, 5): return 5 return ChooseRandomMoveFromList (board, [2,4,6,8]) def is BoardFull (board): # This function returns true if all space on board has been taken for i in range (1,10): if isSpaceFree (board, i): return False return True print (“Welcome to Tic-Tac-Toe !”) while True: the Board = [” * 10 playerletter, computerletter = input playerletter() turn = whoGoesFirst() print (‘The’ + turn + ‘will go first.’) gamelsPlaying = True while gemelsPlaying: if turn = = ‘player’: drawBoard (theBoard) move = getPlayerMove (theBoard) makeMove (theBoard, playerletter, move) if is Winner (theBoard, playletter): drawBoard (theBoard) print (‘Hooray ! You have won !’) gamelsPlaying = False esle: if is BoardFull (theBoard): drawBoard (theBoard) print (‘The game is a tie.”) break else: turn = ‘computer’ else: move=getCompterMove(theBoard, Computerletter) makeMove (theBoard, computer letter, move) if is Winner (theBoard, computerletter): drawBoard (theBoard) print(‘The computer has beaten you!’) gamelsPlaying = False else: if isBoardFull (theBoard): drawBoard (theBoard) print (‘The game is a tie !’) break else: turn = ‘player’ if not play Again (): break |
|
| 787. |
Explain exp(x) in python with example. |
|
Answer» Description : The method exp( ) returns exponential of x : ex. Example: Syntax: Following is the syntax for exp() method import math math.exp(x) Note: This function is not accessible directly so w e 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 exponential of x: ex. Example: The following example shows the usage of exp() method # !/usr/bin/py thon import math # This will import math module print “math.exp(-45.17): “, math.exp(-45.17) print “math.exp(100.12):”, math.exp(100.12) print “math.exp(100.72):”, math.exp(100.72) print “math.exp(119L):”, math.exp(119L) print “math.exp(math.pi):”, math.exp(math.pi), This will produce the following result math.exp(-45.17):2.41500621326e-20 math.exp(100.12):3.03084361407e+43 math.exp(100.72): 5.52255713025e+43 math.exp(119L):4.7978133273e+51 math.exp(math.pi): 23.1406926328 |
|
| 788. |
If `af(x)+bf((1)/(x))=(1)/(x)`, where `anebandxne0`, find f(x). |
|
Answer» We have, `af(x)+bf((1)/(x))=(1)/(x)" "…..(i)`. Replacing x by `(1)/(x)` in (i), we get `af((1)/(x))+bf(x)=x" "…..(ii)` Adding (i) and (ii), we get `a{f(x)+f((1)/(x))}+b{f(x)+f((1)/(x))}=(x+(1)/(x))`. `implies(a+b){f(x)+f((1)/(x))}=(x+(1)/(x))` `impliesf(x)+f((1)/(x))=(1)/((a+b))(x+(1)/(x))." "....(iii)` On subtracting (ii) from (i), we get `a{f(x)-f((1)/(x))}-b{f(x)-f((1)/(x))}=((1)/(x)-x)` `implies(a-b){f(x)-f((1)/(x))}=((1)/(x)-x)` `{f(x)-f((1)/(x))}=(1)/((a- b))((1)/(x)-x)." "......(iv)` On adding (iii) and (iv), we get `2f(x)={(x)/((a+b))-(x)/((a-b))}+{(1)/((a+b)x)+(1)/((a-b)x)}` `=((a-b)x-(a+b)x)/((a^(2)-b^(2)))+((a-b)+(a+b))/((a^(2)-b^(2))x)` `=(-2bx^(2)+2d)/((a^(2)-b^(2))x)=(2)/((a^(2)-b^(2)))((a)/(x)-bx)`. Hence, `f(x)=(1)/((a^(2)-b^(2)))((a)/(x)-bx)`. |
|
| 789. |
If `X={1,2,3,4},` then one-one onto mappings `f:X to X` such that `f(1)=1, f(2) ne 2 f(4) ne 4` are given byA. {(1,1),(2,3),(3,4),(4,2)}B. {(1,1),(2,4),(3,3),(4,2)}C. {(1,1),(2,4),(3,2),(4,3)}D. none of these |
|
Answer» Correct Answer - D Clearly, mappings given in options (a),(b) and (c ) satisfy the given conditions and are one-one onto. |
|
| 790. |
Let `A={1,2,..., n}`and `B={a , b`}. Then number of subjections from `A`into `B`isnP2 (b) `2^n-2`(c) `2^n-1`(d) nC2A. `^(n)P_(2)`B. `2^(n)-2`C. `2^(n)-1`D. none of these |
|
Answer» Correct Answer - B The total number of mappings from A to B is `2^(n)` of which two 2 mappings f(x)=a for all x satisfying `1 le x lt n` and g(x)=b for all x satisfying `1 le x le n` are not surjective. Thus, the number of surjective mappings is `2^(n)-2` |
|
| 791. |
Let f be the exponential function and g be the logarithumic function. Then, find (i) (f+g)(1) (ii) (fg)(1) (iii) (4f)(1) (iv) (3g)(1) |
|
Answer» Let `f:RtoR:f(x)=e^(x)andg:R^(+)toR:g(x)=log_(e)x`. Then, dom `(f)nn"dom "(g)=RnnR^(+)=R^(+)`. (i) `(f+g):R^(+)toR` is given by `(f+g)(x)=f(x)+g(x)=(e^(x)+log_(e)x)`. `:.(f+g)(1)=(e^(1)+log_(e)1)=(e+0)=e`. (ii) `(fg):R^(+)toR` is given by `(fg)(x)=f(x).g(x)=e^(x)(log_(e)x)`. `:.(fg)(1)=e^(1)(log_(1)1)=(exx0)=0`. (iii) `(4f):R^(+)toR` is given by `(4f)(x)=4xxf(x)=4e^(x)`. `:.(4f)(1)=(4xxe^(1))=4e^(x)`. (iv) `(3g):R^(+)toR` is given by `(3g)(x)=3xxg(x)=3xx(log_(e)x)`. `:.(3g)(1)=3xxg(1)=3xx(log_(e)1)=(3xx0)=0`. |
|
| 792. |
List down the advantages of modular programming. |
|
Answer» Merits of modular programming
|
|
| 793. |
If char name [ ] = “Rajeev Kumar”; then what will be output of the following statement? cout<<strlen(name) |
|
Answer» The length(number of characters) is 12 including space. |
|
| 794. |
Consider the following code:char S1[ ] = “program”char S2[ ] = “PROGRAM” int n;n=strcmpi (S1 , S2)What is the value of n?(a) n=0 (b) n=1 (c) n>1 (d) n<0 |
|
Answer» n = 0 is the value of n. |
|
| 795. |
After the distribution of answer scripts, the teacher gives the Photostat copy of the mark list to the students to check the marks. If the students make any change that do not affect the original mark list. There is a similar situation to pass the arguments to a function. What is this method? (a) call by value (b) call by reference (c) call by address (d) none of these |
|
Answer» (a) call by value |
|
| 796. |
How does C++ support modularity in programming. |
|
Answer» The process of converting big programs into smaller programs is known as modularisation. This small programs are called modules or sub programs or functions. C++ supports modularity in programming called functions. |
|
| 797. |
void initialise(){int k = 10;}int main(){int a, b;float marks;a = 20;cout<<"First value="<<a;initialise();b = k + a;cout<<"New value="<<b;}1. Identify the error in the, above code and explain its reasons. 2. Correct the errors |
|
Answer» 1. K is a local variable in the function initialize() – It is not accessible in main() 2. Making the variable K as global we can correct the error. |
|
| 798. |
Consider the following C++ statement and answer the following question: char Word[10]=”GOOD DAY”; Identify the correct output statement to display the string (a) write (word); (b) cout.write(word); (c) cout (word);(d) cout.write (word, 10); |
|
Answer» (d) cout.write(wond, 10); |
|
| 799. |
The following assignment statement will generate a compilation error. char str[20]; str=”Computer” Write a correct C++ statement to perform the same task |
|
Answer» char str[20] = “Computer”; OR char str[20]; strcpy(str,”Computer”); (The header le should be included). |
|
| 800. |
What are the jobs of a return statement in a program. |
|
Answer» In the case of a sub function a return statement helps to terminate the sub function and return back to the main function or called function. But in the case of a main function it terminates the program. |
|