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.

  1. Which of the following are valid Python identifiers?
    1. N1
    2. N_1
    3. N.1
    4. N-1
    5. Zzzzzzz
    6. SumUp
    7. Good_Show
    8. Number
    9. NUMBER
    10. RateOfIncrease
    11. 2Good2BeTrue
    12. XYZ
  2. Convert each of the following (non-Python) expressions into Python expressions:
    1. 3x
    2. 3x + y
    3. x is evenly divisible by 12
    4. x plus 7 is more than 100 or else x is less than fifty
    5. xy and 2 ≤ z
  3. Assuming num = 20, determine the value of each of the following Python expressions:
    1. num / 12
    2. 123 % 100
    3. 8 + 3 * 7
    4. (0 == 1) and (2 < 3)
    5. not ((4.5 < 12.9) and (6 * 2 <= 13))
    6. (0 ==1) or ( 2 < 3)
    7. (0 == 1) or (2 < 3) and (7 < 6)
    8. (2 < 3) or (0 == 1) and (7 < 6)
  4. 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'
    
  5. 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
    
  6. 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
    
  7. 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.
  8. 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.