Contents

  1. area.py
  2. input_demo.py

area.py 1/2

[
top][prev][next]
# Finds the area of a rectangle
# by CS111 class, 9/14/2012

# prompt the user for input
width = eval(input("What is the width of the rectangle in cm? "))
height = eval(input("What is the height of the rectangle in cm? "))

# to calculate the area, multiply the height by the width
area = width * height

print("area =", area, "cm^2")

input_demo.py 2/2

[
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.