Last active
December 28, 2015 12:19
-
-
Save mattjbarlow/7500217 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hello(): | |
print 'Hello!' | |
def area_rectangle(width, height): | |
return width * height | |
def area_square(side): | |
return side*side | |
def area_circle(radius): | |
return 3.14* radius ** 2 | |
def print_welcome(name): | |
print 'Welcome,', name | |
def print_options(): | |
print " 'r' get area of a rectangle" | |
print " 's' get area of a square" | |
print " 'c' get area of a circle" | |
print " 'q' quit" | |
def get_choice(): | |
option = 'p' | |
while option != 'q': | |
if option == 'r': | |
print_rectangle() | |
elif option == 's': | |
print_square() | |
elif option == 'c': | |
print_circle() | |
print_options() | |
option = raw_input("option: ") | |
def print_rectangle(): | |
print 'To find the area of a rectangle,' | |
print 'enter the width and height below.' | |
w = input('Width: ') | |
while w <= 0: | |
print 'Must be a positive number' | |
w = input('Width: ') | |
h = input('Height: ') | |
while h <= 0: | |
print 'Must be a positive number' | |
h = input('Height: ') | |
print 'Width =', w, 'Height =', h, 'so Area =', area_rectangle(w, h) | |
def print_square(): | |
print 'To find the area of a square,' | |
print 'enter the length of a side below.' | |
w = input('Side: ') | |
while w <= 0: | |
print 'Must be a positive number' | |
w = input('Side: ') | |
print 'Side =', w, 'so Area =', area_square(w) | |
def print_circle(): | |
print 'To find the area of a circle,' | |
print 'enter the length of the radius below.' | |
w = input('Radius: ') | |
while w <= 0: | |
print 'Must be a positive number' | |
w = input('Radius: ') | |
print 'Radius =', w, 'so Area =', area_circle(w) | |
name = raw_input('Your Name: ') | |
hello(), | |
print_welcome(name) | |
get_choice() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment