What does function subroutine do?
def subroutine(n):
while n > 0:
print (n,)
n -= 1
Select one:
a. Counts from 10
down to 0 and displays each number
down to 0 and displays each number
b. Counts from n down
to 1 and displays each number
to 1 and displays each number
c. Calculates the sum
of n numbers greater than 0
d. Calculates the
mean of n
of n numbers greater than 0
d. Calculates the
mean of n
What output will the following code produce?
def area(l, w):
temp = l * w;
return temp
l = 4.0
w = 3.25
x = area(l, w)
if ( x ):
print (x)
Select one:
a. 13.0
b. 0
c. Expression does
not evaluate to boolean true
d. 13not evaluate to boolean true
Repeated execution of a set of programming statements is
called repetitive execution.
called repetitive execution.
Select one:
True
False
A stack diagram shows the value of each variable and the
function to which each variable belongs.
function to which each variable belongs.
Select one:
True
False
The following code is an example of what principle?
bruce = 5
print (bruce,)
bruce = 7
print (bruce)
Select one:
a. Multiple
assignment
assignment
b. An Iteration or
loop structure
loop structure
c. A logical operator
d. A conditional
expression
expression
What does function subroutine do?
def subroutine(n):
while n > 0:
print (n,)
n -= 1
Select one:
a. Counts from 10
down to 0 and displays each number
down to 0 and displays each number
b. Counts from n down
to 1 and displays each number
to 1 and displays each number
c. Calculates the sum
of n numbers greater than 0
of n numbers greater than 0
d. Calculates the
mean of n
mean of n
Expressions evaluate to either true or false. What will the output of the following code be
when the expression (Ni!) is evaluated?
when the expression (Ni!) is evaluated?
if "Ni!":
print ('We are the
Knights who say, "Ni!"')
Knights who say, "Ni!"')
else:
print ("Stop
it! No more of this!")
it! No more of this!")
Select one:
a. Stop it!
b. We are the Knights
who say, "Ni!
who say, "Ni!
c. Stop it! No more
of this!"
of this!"
d. No output will be
produced
produced
What will the output of the following code be?
def recursive( depth ):
depth+=1
while (depth <
5):
5):
ret =
recursive(depth)
recursive(depth)
return depth
ret = recursive( 0 )
print ("the recursive depth is ", ret)
Select one:
a. the recursive
depth is 5
depth is 5
b. the recursive
depth is 4
depth is 4
c. Error due to depth
of recursive calls
of recursive calls
d. None
Encapsulation is the process of wrapping a piece of code in
a function
a function
Select one:
True
False
What output will the following python commands produce:
x=1
y=2
if x == y:
print (x,
"and", y, "are equal")
"and", y, "are equal")
else:
if x < y:
print (x,
"is less than", y)
"is less than", y)
else:
print (x,
"is greater than", y)
"is greater than", y)
Select one:
a. 1 and 2 are equal
b. 1 is less than
2
2
c. 1 is greater than
2
2
d. 2 is greater than
1
1
No comments:
Post a Comment