Python - Test Yourself4

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
 b. Counts from n down
to 1 and displays each number
 
 c. Calculates the sum
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. 13


Repeated execution of a set of programming statements is
called repetitive execution.

Select one:
 True
 False  

A stack diagram shows the value of each variable and the
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 
 b. An Iteration or
loop structure
 c. A logical operator
 d. A conditional
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
 b. Counts from n down
to 1 and displays each number 
 c. Calculates the sum
of n numbers greater than 0
 d. Calculates the
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?

if "Ni!":
    print ('We are the
Knights who say, "Ni!"')
else:
    print ("Stop
it! No more of this!")

Select one:
 a. Stop it!
 b. We are the Knights
who say, "Ni! 
 c. Stop it! No more
of this!"
 d. No output will be
produced

What will the output of the following code be?

def recursive( depth ):
    depth+=1
    while (depth <
5):
        ret =
recursive(depth)
    return depth

ret = recursive( 0 )
print ("the recursive depth is ", ret)

Select one:
 a. the recursive
depth is 5
 b. the recursive
depth is 4
 c. Error due to depth
of recursive calls
 d. None  

Encapsulation is the process of wrapping a piece of code in
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")
else:
    if x < y:
        print (x,
"is less than", y)
    else:
        print (x,
"is greater than", y)


Select one:
 a. 1 and 2 are equal
 b. 1 is less than
 c. 1 is greater than
2
 d. 2 is greater than
1


No comments:

Post a Comment