Contents
- area.py
- arith_practice.py
- debug_practice.py
- input_demo.py
area.py 1/4
[top][prev][next]
# Calculate the area of a rectangle
# by CS111, 01/11/2008
print "This program calculates the area of a rectangle."
# First, just assign width and height values.
# Then, get from user
#width = 3.5
#height = 2.2
width = input("Enter the width of the rectangle: ")
height = input("Enter the height of the rectangle: ")
area = width * height
print "The area of the rectangle is", area
arith_practice.py 2/4
[top][prev][next]
# Arithmetic practice
#
#
print 5+3*2
print 2 * 3 ** 2
print -3 ** 2
print 2 ** 3 ** 2
debug_practice.py 3/4
[top][prev][next]
# Program to exercise our debugging skills
# Contains one syntax error and two runtime exceptions
# By Sara Sprenkle, 09/14/07
x = 10
y = 7
z = x + v
a = 15
c = 8
b = a - 7
b = b - c
z = c/b
print The answer is ", z
input_demo.py 4/4
[top][prev][next]
# Demonstrate numeric and string input
# by Sara Sprenkle for CS111 on 1/8/08
color = raw_input("What is your favorite color? ")
print "Cool! My favorite color is _light_", color, "!"
scale = input("On a scale of 1 to 10, how much do you like Matt Damon? ")
print "Cool! I like him", scale*1.8, "much!" # always likes him more
Generated by GNU enscript 1.6.4.