Question 1
Question
What does the function subroutine do?
def subroutine(n):
while n>0:
print(n,)
n-=1
Answer
-
Counts down from 10 to 0 and displays each number
-
Counts from n down to 1 and displays each number
-
Calculates the sum of n numbers greater than 0
-
Calculates the mean of n
Question 2
Question
What output will the following python command produce:
>>>percentage = float (60*100)/50
>>>print(percentage)
Answer
-
percentage
-
109
-
109.0909090909091
-
109.0
Question 3
Question
What outputs will the following python commands produce:
n=10000
count=0
while n:
count=count+1
n=n//10
print(count)
Question 4
Question
What output will the following python commands produce:
x=5
if x%2==0:
print(x)
else:
print(x,x%2)
Question 5
Question
What is the output of the following statements?
pi=float(3.14159)
print(pi)
Question 6
Question
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!")
Answer
-
Stop it!
-
We are the knights who say, "Ni!"
-
Stop it! No more of this!
-
No output will be produced
Question 7
Question
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)
Answer
-
1 and 2 are equal
-
1 is less than 2
-
1 is greater than 2
-
2 is greater than 2
Question 8
Question
The following code is an example of what principle?
bruce=5
print(bruce,)
bruce=7
print(bruce)
Question 9
Question
The % or modulus operator returns the remainder present when two integers do not divide evenly into one another
Question 10
Question
An algorithm is a step by step process for solving a problem
Question 11
Question
Functions allow the programmer to encapsulate and generalize sections of code.
Question 12
Question
One way to generalize a function is to replace a variable with a value.
Question 13
Question
A variable name defined in a function cannot appear in the calling program because it will cause a conflict error.