Professional Documents
Culture Documents
Program 1:
1. What output data type will this function return? How do you reveal the data type
from the given function’s declaration and definition? Elaborate your answer.
*Solution
The datatype of the output will be boolean. If we declare the output will be always in
Bolean. We are simply returning True and False from the definition, which is either 1
or 0. The return type is therefore boolean(1 or 0).
2. What data types have been respectively declared for variables, data and val? In terms
of the programming scope, are variables, data and val used locally or globally?
*Solution
The data types and val of variables are both of int type.
The data and the val are locally declared in terms of programming scope.
They are limited to use to this function exclusively.
3. Variables, data and val are both used to store data but they store different numbers of
data value. How many data value(s) have variables data and val stored respectively?
Which of them is an array? Why? Elaborate your answer.
*Solution
4. What is the purpose of the variable, i in the function? Is it a local or global variable?
What is the data type declared for it?
*Solution
i has two purposes: iterating the for loop and setting up a condition to end the loop
based on i.
i is a local variable. This is declare inside the function.
i is integer data type.
5. What would be returned value if the function is called with the data in sample data 1?
*Solution
If the function is used with sample data 1, False would be returned because val is not
present sample data 1
5 is not present in sample data 1.
6. What would be returned value if the function is called with the data in sample data 2?
*Solution
7. Deduce the purpose of this function after two sample datasets are executed through it.
Provide an appropriate name (meaningful name aligned with the purpose) for this
function. Hint: Recall the output data type in your provided answer for the question 1
in this section – Program 1, think about how it could provide the expected outcome.
*Solution
In second dataset 2, result will be 3 as there are total three '8' present.
For i = 0 To data.Length - 1
End If
End For
Return False
End Function
Program 2:
What will be output to the terminal when the program is run? Hint: make sure you have
traced all print statements along the program flow. The first two print-out lines are given as
below.
*Solution
Starting…
ADDING 32 + 6
SUBTRACT 78-5
total= 38 difference: 73
I like bananas
I like orange
I like figs
I like lemons
My favourite fruit is oranges
1. What are the data types respectively of the following variables? Since data types are not
declared in Python source code, how did you reveal their data types in a Python
program?
*Solution
Identifier Data type How did you reveal their data type in a Python program?
total int Total=add(32,6) gives 38, and when printing, it uses %d,
which stands for integer.
differenc int Difference=Subtract(78,5) returns an integer number, and
e when printing, it uses the integer symbol %d.
Program 3:
1. What will be output to the terminal when the program is run? Hint: make sure you have
traced all print statements along the program flow. The first two print-out lines are given
as below.
*Solution
*Solution
*Solution
4. What do you think the difference is between the keywords let and var? Hint: Deduce
from how they are used in the program. Think about whose value will ever be adjusted
throughout the program?
*Solution