Practice Questions
Practice Questions
2. What type of volatile memory is usually used only for temporary storage while running a
program?
a. ROM
b. TMM
c. RAM
d. TVM
4. The __________ function reads a piece of data that has been entered at the keyboard and returns that
piece of data, as a string, back to the program.
a. input()
b. output()
c. eval_input()
d. str_input()
5. When using the __________ logical operator, both of the subexpressions must be true for the
compound expression to be true.
a. Or
b. And
c. Not
d. Maybe
6. A(n) __________ is a diagram that graphically depicts the steps that take place in a program?
a. flowchart
b. algorithm
c. source code
d. pseudocode
7. What is the result of the following Boolean expression, given that x = 3, y = 2, and z = 18?
x < y or z < x
a. True
b. False
c. 8
d. 5
9. What is the output of the following statement, given that value1 = 2.0 and value2 = 12?
print(value1 * value2)
a. 24
b. value1 * value2
c. 24.0
d. 2.0 * 12
11. Which of the following is the correct if clause to determine whether choice is anything other
than 10?
a. if choice != 10:
b. if choice != 10
c. if choice <> 10:
d. if not(choice < 10 and choice > 10):
def magic(num):
answer = num + 2 * 10
return answer
if __name__ == '__main__':
main()
a. 70
b. 25
c. 100
d. The statement will cause a syntax error.
16. Which of the following describes the base case in a recursive solution?
a. a case in which the problem can be solved without recursion
b. the case in which the problem is solved through recursion
c. the way to stop the recursion
d. the way to return to the main function
18. Which of the following statements about break and continue is NOT correct?
a. both break and continue are keywords in Python
b. both are used with loops
c. break statement terminates the loop
d. continue statement terminates the loop
19. What are the values that the variable num contains through the iterations of the following for loop?
for num in range(4):
a. 1, 2, 3, 4
b. 0, 1, 2, 3, 4
c. 1, 2, 3
d. 0, 1, 2, 3
20. Which would be the base case in a recursive solution to the problem of finding the factorial of a
number. Recall that the factorial of a non-negative whole number is defined as n! where:
If n = 0, then n! = 1
If n > 0, then n! = 1 x 2 x 3 x ... x n
a. n=0
b. n=1
c. n>0
d. The factorial of a number cannot be solved with recursion.
Part 2:
Question 1: Write a loop to calculate the total (sum) of all numbers between 50 and
5000 that can be divided by 17?
Question 2: Write a program that displays a table of the Celsius temperatures 0
through 20 and their Fahrenheit equivalents. The formular for converting a
temperature from Celsius to Fahrenheit is
9
F= C +32
5
Where F is the Fahrenheit temperature and C is the Celsius temperature. Your
program must use a loop to display the table.
Question 3: Write a program to find out how many numbers between 1 and 100
inclusively such that can be dividable by either 3 or 7? (Use remainder operator %
to find out if a number is dividable by another number, we say n is dividable by m if
n % m is zero, i.e. no remainder )
Question 5: Write a recursive function that accepts a base and n that are positive
numbers, compute recursively (no loops) the value of base to the n power, so
powerN(3, 2) is 9 (3 squared).
def powerN( base, n ) :