Contents

  1. birthyear.py
  2. evenorodd.py
  3. speedlimit.py

birthyear.py 1/3

[
top][prev][next]
# Example of if/elif/else 
# Calculates a person's birthyear, given the current year and their age.
# by CS111, 09/28/07

print "This program determines your birth year"
print "given your age and current year"
print
age = input("Enter your age >> ")

if age > 110:
    print "Don't be ridiculous, you can't be that old."
else:
    currentYear = input("Enter the current year >> ")
    birthyear = currentYear - age
    print
    print "You were either born in", birthyear, "or", birthyear-1

evenorodd.py 2/3

[
top][prev][next]
x = input("Enter a number: ")
if x%2 == 0 :
    print x, "is even"
if  x%2 == 1:
    print x, "is odd"

speedlimit.py 3/3

[
top][prev][next]
# Calcuate speeding ticket fines
#
#

# Prompt the user for input

speedlimit = input("What was the speed limit? " )
clockspeed = input ("What was the clock speed? ")

# Check if speeding
if clockspeed > speedlimit :
    # TRUE: Calculate the fine
    basefine = 50 + (clockspeed - speedlimit ) * 5
    if clockspeed > 90 :
        basefine += 200
    # print the fine
    print "The fine is $", basefine
else: 
    # FALSE: print nice message
    print "You are fine, upstanding citizen"

Generated by GNU enscript 1.6.4.