Contents

  1. area.py
  2. debug_practice.py
  3. input_demo.py

area.py 1/3

[
top][prev][next]
# Finds the area of a rectangle
# by CS111 class, 1/17/2011

# Get the width and the height
width=input("Enter the width of the rectangle: ")
height=input("Enter the height of the rectangle: ")

# Calculate the area (from the width and the height)
area = width*height

# Display the area
print "The area of the rectangle is", area

debug_practice.py 2/3

[
top][prev][next]
# Program to exercise our debugging skills.
# Contains one syntax error and two runtime exceptions.
# By Sara Sprenkle

x = 10
v = 7
z = x + v

a = 15
c = 8
b = a - 7
b = b - c + 1

z = c/b

print "The answer is ", z


input_demo.py 3/3

[
top][prev][next]
# Demonstrate numeric and string input
# by Sara Sprenkle for CS111

color = raw_input("What is your favorite color? ")
print "Cool!  My favorite color is _light_", color, "!"

rating = input("On a scale of 1 to 10, how much do you like Matt Damon? ")
print "Cool!  I like him", rating*1.8, "much!"


Generated by GNU enscript 1.6.4.