# ------------------------------------------------------------ #Student: Austin Wells #Class: CIS122 #Date: 4/29/2015 #Program Title: Chapter 6 Programming Excercise 1.py #(Rectangle Area) #Program Description: The program prompts the user for the width and length #of a rectabgle and displays the area # ------------------------------------------------------------ # prints the area of the rectangle def printRect(area): print 'The area of the rectangle is {}' .format(area) # prompts user for input. def promptForNumber(strPrompt): userInput = int(raw_input(strPrompt + ": ")) print '{}' .format(userInput) return userInput #calculates the area of a Rectangle def calculateRect(widthVar,lengthVar): area = widthVar * lengthVar return area #main driver function def main(): try: widthVar = promptForNumber("Please enter the width of a rectangle") lengthVar = promptForNumber("Please enter the length of a rectangle") printRect(calculateRect(widthVar,lengthVar)) except (ValueError): print '\n\nInvalid input. You have entered a non integer. Please enter an objects mass' except (EOFError): print '\n\nInvalid input. You have forgotten to add input. Please Reset the program and enter the width and length of the rectangle' main()
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