Contents
- area.py
- debug_practice.py
- helloworld.py
- input_demo.py
area.py 1/4
[top][prev][next]
# Finds the area of a rectangle
# by CS111 class, 1/16/2012
# Get the input, width and height
width = eval(input("What is the width? "))
height = eval(input("What is the height? "))
# Calculate the area
area = width*height
# Print the area
print("The area of your rectangle is", area)
debug_practice.py 2/4
[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
# changed below line from b - 8
b = a - 8
# changed below line from b - c + 1
b = b - c + 2
z = c/b
# changed from print("The answer is, z)
print("The answer is", z)
helloworld.py 3/4
[top][prev][next]
# Displays a greeting
# Sara Sprenkle, 01.2012
print("Hello, class!")
print("Your answer is", 4*4)
input_demo.py 4/4
[top][prev][next]
# Demonstrate numeric and string input
# by Sara Sprenkle for CS111
color = input("What is your favorite color? ")
print("Cool! My favorite color is _light_", color, "!")
rating = eval(input("On a scale of 1 to 10, how much do you like Ryan Gosling? "))
print("Cool! I like him", rating*1.8, "much!")
Generated by GNU enscript 1.6.4.