print def print_options(): print "Options:" print " 'p' print options" print " 'rectangle'" print " 'circle'" print " 'square'" print " 'q' quit the program" def hello(): print 'Hello!' def area(width, height): return width * height def area_cir(radius): return 3.14 * radius ** 2 def area_squ(side): return side ** 2 def print_welcome(name): print 'Welcome,', name name = raw_input('Your Name: ' + '\n') hello(), print_welcome(name) choice = "p" while choice != "q": if choice == "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(w, h) elif choice == "circle": print print 'To find the area of a circle,' print 'enter the radius below.' print r = input('Radius: ') while r <= 0: print 'Must be a positive number' r = input("Radius: ") print 'Radius =', r, 'so Area =', area_cir(r) elif choice == "square": print print 'To find the area of a square,' print 'enter the any side length below.' print s = input('Side length: ') while w <= 0: print 'Must be a positive number' s = input('Side length: ') print 'Side length =', s, 'so Area =', area_squ(s) elif choice != "p": print_options() choice = raw_input("What sort of shape would you like to find the area of? ") print "Goodbye!"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question