Skip to content

Instantly share code, notes, and snippets.

@mattjbarlow
Last active December 28, 2015 12:19
Show Gist options
  • Save mattjbarlow/7500217 to your computer and use it in GitHub Desktop.
Save mattjbarlow/7500217 to your computer and use it in GitHub Desktop.
print
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
print 'To find the area of a rectangle,'
print 'enter the width and height below.'
print
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
print 'To find the area of a square,'
print 'enter the length of a side below.'
print
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
print 'To find the area of a circle,'
print 'enter the length of the radius below.'
print
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