Review Questions for Exam 1
This review sheet is intended to give you some practice questions to
use in preparing for our first midterm. It is not necessarily complete.
The first exam covers the reading assignments, programming projects and
class/discussion material through Friday 2/22.
This sheet will be updated after class on 2-20.
1. What is a CPU?
2. Give one example of an input device and one example of an output
3. What is a compiler?
4. Write an algorithm that displays the sum of all numbers which are
multiples of 3 between 1 and 1000. Now translate your algorithm into
5. Write a line of code that reads a line of text from the user.
6. Write a line of Python code that reads a floating-point number from
7. Assume that val is an initialized variable of type float. Write a
Python statement that prints val to the console window. Display 3
after the decimal point.
8. Write a complete Python program that reads 100 floating-point
numbers from the user, and
prints the max, min and average value.
9. Write a Python program that reads 20 lines of text from the user and
prints the number of lines that contain the phrase "happy day".
10. Write a Python program that reads a line of text from the keyboard
and prints its reverse to the screen.
11. Write a function that takes (as a parameter) an integer variable
num and returns the sum of the integers between 0 and num.
12. What is the value and type of the result?
e. ("a" == "a") and ("b" != "B")
g. str(15 + 2) + " hellos"
h. 15 * 2 / 4
i. (5 < 4) or (not 3 == 3)
13. Write a Python program that reads positive integers from the user,
stopping when the user enteres a 0 or negative integer, and prints the
average of the positive integers.
14. Explain how the functions str(), float(), int() work. Give an
example of how you would use one of them.
15. Write a for loop that prints the multiples of 3 between 3 and 90.
16. Write a few lines of code that reads 2 strings from the user, and
prints a message indicating whether or not they are the same string.
17. Give an example that illustrates how the find() function works. (We
haven't covered find() yet - save this question for our next exam).
18. Write a few lines of code that read an integer from the user, and
then prints the digits in the number, one per line.
19. Write an if-elif-else statement that prints a message indicating
the value stored in int variable n is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 or
20. Consider writing code that prints the squares of the numbers
between 1 and n, where n is a value entered by the user. Do this with a
a. for loop
b. while loop
If the user enters an integer less than 1, print an error message.
21. Write a function that takes a string as its argument, and returns
the reverse of the string. That is, if the argument is "happy day",
then the function returns the string "yad yppah". Then write a main
function that reads 15 strings from the user and prints the reverse of
22. Write a function that takes a positive integer and returns the ones
digit of the integer.
23. Write a program that reads a string from the user, and prints the
string, one character per line.