0% found this document useful (0 votes)
10 views5 pages

Practice Questions

Uploaded by

stookslexi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Practice Questions

Uploaded by

stookslexi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CISC 131 Midterm practice

Part 1. MULTIPLE CHOICE

1. Programs are commonly referred to as


a. system software
b. software
c. application software
d. utility programs

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

3. In Python the __________ symbol is used as the not-equal-to operator.


a. ==
b. <>
c. <=
d. !=

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

8. A Boolean variable can reference one of two values which are


a. yes or no
b. True or False
c. T or F
d. Y or N

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

10. The first line in a function definition is known as the function


a. Header
b. Block
c. Return
d. parameter

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):

12. What does the following program do?


student = 1
while student <= 3:
total = 0
for score in range(1, 4):
score = int(input("Enter test score: "))
total += score
average = total/3
print("Student ", student, "average: ", average)
student += 1
a. It accepts 4 test scores for 3 students and outputs the average of the 12 scores.
b. It accepts 3 test scores for each of 3 students and outputs the average for each student.
c. It accepts 4 test scores for 2 students, then averages and outputs all the scores.
d. It accepts one test score for each of 3 students and outputs the average of the 3 scores.

13. What will be displayed after the following code is executed?


count = 4
while count < 12:
print("counting")
count = count + 2
a. counting counting counting counting
b. counting
counting
counting
counting
c. counting
counting
d. counting
counting
counting

14. A value-returning function is


a. a single statement that performs a specific task
b. called when you want the function to stop
c. a function that will return a value back to the part of the program that called it
d. a function that receives a value when called

15. What will display after the following code is executed?


def main():
print("The answer is", magic(5))

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

17. Recursive functions are __________ iterative algorithms.


a. more efficient than
b. less efficient than
c. as efficient as
d. impossible to compare to

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 4: Write a program to calculate sum below and display it (print):

∑ ¿12 +22 +32 + 42 +…+10 2

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 ) :

You might also like