Sample Final Questions
The part of the final dealing with material covered before the midterm will be small, 2-4 questions at most. The final will emphasize material from May 9 (Programming languages and the Windows System) on. Some of the questions will be on the Python parts of the course. These questions will explore various aspects of Python and of programming. The central themes are writing a program, data types (with variables), operators, selection, and looping. These questions are sample Python questions. The other questions will be like the ones asked on the midterm.
-
Which of the following are valid Python identifiers?
- N1
- N_1
- N.1
- N-1
- Zzzzzzz
- SumUp
- Good_Show
- Number
- NUMBER
- RateOfIncrease
- 2Good2BeTrue
- XYZ
-
Convert each of the following (non-Python) expressions into Python expressions:
- 3x
- 3x + y
-
-
- x is evenly divisible by 12
- x plus 7 is more than 100 or else x is less than fifty
- x ≤ y and 2 ≤ z
-
Assuming num = 20, determine the value of each of the following Python expressions:
- num / 12
- 123 % 100
- 8 + 3 * 7
- (0 == 1) and (2 < 3)
- not ((4.5 < 12.9) and (6 * 2 <= 13))
- (0 ==1) or ( 2 < 3)
- (0 == 1) or (2 < 3) and (7 < 6)
- (2 < 3) or (0 == 1) and (7 < 6)
-
Write the output produced by this program below.
x = 3
if 2 > x :
print 'First'
else :
print 'Second'
if 2 > x :
print 'Third'
print 'Fourth'
print `Fifth'
-
Write the output produced by this program below.
words = 'this IS NoT EvEN'
print words.title()
print words.replace("IS", 'was')
print words.upper()
print words * 2
-
Find the error in the following program.
line = raw_input("Type a word")
print "You typed", line
line = line + "h"
num = int(line)
print "You typed the number ", num
-
Outline a program that will prompt a user to enter a temperature as an integer. Your program will print "it is hot" is the temperature is over 100, "it is cold" if the temperature is under 60, and "it is just right" if the temperature is between 61 and 99 inclusive. The program continues to ask for termperatures, and evaluates them as above, until the user enters a temperature of 0.
-
Write a Python program that does the above. Here is what the output should look like:
Please enter a temperature: 95
It is just right.
Please enter a temperature: 110
It is hot.
Please enter a temperature: 32
It is cold.
Please enter a temperature: 0
Good bye!
Here is a PDF version of this document.