Chapter 3 - Type B - Application Based Questions
Chapter 3 - Type B - Application Based Questions
1. What are the errors in following codes? Correct the code and predict output:
(a) Answer
In line 3 & 4 there should be double indentation. Return should be present inside the
subprogram.
(b) Answer - In line 5 "RETURN" should be in small words and also there is only one
indentation
3. Consider the following code and write the flow of execution for this. Line numbers
have been given for your reference.
Answer - When arguments are passed in addEm(x, y, z) then it add all the arguments and
print the result. It is void Function.
Answer-When function called then it will add all the argument and it will show nothing.
Because return keyword will work before print statement.
6. What will be the output of following programs?
2
CODE 1 OUTPUT CODE 2 OUTPUT
OUTPUT -
Answer - Return is written before print , so when function will call then print statement will
not give any result. Function call is not present in the program.
9. Write a function namely fun that takes no parameters and always returns None.
Answer
def fun() :
print("fun")
return
Output:-
None
10. Consider the code below and answer the questions that follow:
Answer
Output:-
5 times 5 = 25
4
11. Consider the code below and answer the questions that follow:
Answer - It will show no result. Because return statement is written before print statement.
(a)
def minus (total, decrement)
output = total - decrement
print(output)
return (output)
(b) Answer
define check()
N = input ('Enter N: ')
i=3
answer = 1 + i ** 4 / N
Return answer
(c) Answer
5
def alpha (n, string ='xyz', k = 10) :
return beta(string)
return n
print(alpha("Valentine's Day") :)
print(beta (string = 'true' ))
print(alpha(n = 5, "Good-bye") :)
13.Draw the entire environment, including all user-defined variables at the time line 10 is
being executed.
Answer
When line 10 executes then it must be call from line 12. At first line 12 is created in global
environment. Then it call sum and create local environment within global environment. Then sum
function return the values in global environment.
Then line 12 call length and create local environment within global environment. Then length
function return the values in global environment. Then line 12 call mean and create local
environment within global environment. Then mean function call sum and create nested local
environment. Then sum function return values in local environment. Then mean function call
length and create nested local environment. Then length function return values in local
environment.
6
14.Draw flow of execution for above program.
Answer
1 - 6 - 9 -12 - 1 - 2 - 3 - 4 - 12 - 6 - 7 - 12 - 9 - 10 - 1 - 2 - 3 - 4 - 10 - 6 - 7 - 10 - 12
15. In the following code, which variables are in the same scope?
def func1():
a=1
b=2
def func2():
c=3
d=4
e=5
Answer
Here a, b, c, d are in same scope i.e., local scope.
16.Write a program with a function that takes an integer and prints the number that
follows after it: Call the function with these arguments:
4, 6, 8, 2+1, 4 - 3 * 2, -3 - 2
Answer
OUTPUT
7
17.Write a program with non-void version of above function and then write flow of
execution for both the programs.
Answer
Flow of execution:
1-3-1-2-3-4-1-2-4-5-1-2-5-6-1-2-6-7-1-2-7
(i)
Output:-