author | bhanu |
Mon, 15 Nov 2010 15:00:34 +0530 | |
changeset 503 | a858141ad884 |
parent 447 | 694309c7b43c |
permissions | -rw-r--r-- |
447
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
1 |
Objective Questions |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
2 |
------------------- |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
3 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
4 |
.. A mininum of 8 questions here (along with answers) |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
5 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
6 |
1. What will the function do? |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
7 |
:: |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
8 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
9 |
def what(x) |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
10 |
return x*x |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
11 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
12 |
1. Returns the square of x |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
13 |
#. Returns x |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
14 |
#. Function doesn't have docstring |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
15 |
#. Error |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
16 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
17 |
Answer: Error |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
18 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
19 |
2. What will the function do? |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
20 |
:: |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
21 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
22 |
def what(x): |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
23 |
return x*x |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
24 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
25 |
1. Returns the square of x |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
26 |
#. Returns x |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
27 |
#. Function doesn't have docstring |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
28 |
#. Error |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
29 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
30 |
Answer: Returns the square of x |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
31 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
32 |
3. How many arguments can be passed to a python function? |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
33 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
34 |
1. None |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
35 |
#. One |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
36 |
#. Two |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
37 |
#. Any |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
38 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
39 |
Answer: Any |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
40 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
41 |
4. How many values can a python function return? |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
42 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
43 |
1. None |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
44 |
#. One |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
45 |
#. Two |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
46 |
#. Any |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
47 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
48 |
Answer: Any |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
49 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
50 |
5. A python function can return only one value |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
51 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
52 |
1. True |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
53 |
#. False |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
54 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
55 |
Answer: False |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
56 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
57 |
6. What will be the output of the following code? |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
58 |
:: |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
59 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
60 |
def avg(a, b): |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
61 |
return (a + b) / 2 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
62 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
63 |
print avg(10,11) |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
64 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
65 |
1. 10 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
66 |
#. 10.5 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
67 |
#. 11 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
68 |
#. 9.5 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
69 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
70 |
Answer: 10 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
71 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
72 |
7. What will be the output of the following code? |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
73 |
:: |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
74 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
75 |
def avg(a, b): |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
76 |
return (a + b) / 2 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
77 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
78 |
print avg(10,11.0) |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
79 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
80 |
1. 10 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
81 |
#. 10.5 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
82 |
#. 11 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
83 |
#. 9.5 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
84 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
85 |
Answer: 10.5 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
86 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
87 |
8. What will be the output of the following code? |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
88 |
:: |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
89 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
90 |
def what(a, b): |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
91 |
return a + b / 2 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
92 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
93 |
print avg(10,11) |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
94 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
95 |
1. 10 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
96 |
#. 10.5 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
97 |
#. 16 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
98 |
#. 15 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
99 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
100 |
Answer: 15 |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
101 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
102 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
103 |
Larger Questions |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
104 |
---------------- |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
105 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
106 |
.. A minimum of 2 questions here (along with answers) |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
107 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
108 |
1. Write a python function to check the numbers a, b c is a Pythagorean |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
109 |
triplet or not. |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
110 |
|
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
111 |
2. Write a python function which will accept an n digit number and |
694309c7b43c
Added questions for getting started with functions.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
diff
changeset
|
112 |
which returns the reverse of the number. |