# Week 5 Ch 6 Ex 1: # This program uses a function that returns the area of a rectangle # The user is prompted to enter Length and Width and the program calls the function # that calculates the area of the rectangle # Written by Greg Lamb # Last modified on 04/22/2015 def area(width, height): return width*height #Ask user for height and width print("Enter the width and height dimensions at each prompt") width = float(input("Width is: ")) print(width) while width <=0: print("You must enter a postive number") width= float(input("Width is: ")) print(width) height = float (input("Height is: ")) print(height) while height <=0: print ("You must enter a positive number") height= float(input("Height is: ")) print(height) print("Congratulations the function in this program calculated the area of the rectangle to be {} .".format(area(width, height)))
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