forked from besthor/python-example-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectangle_area.py
More file actions
30 lines (25 loc) · 1009 Bytes
/
rectangle_area.py
File metadata and controls
30 lines (25 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
################################################################################
#
# Program: Area of a Rectangle
#
# Description: Compute the area of a rectangle using Python.
#
# YouTube Lesson: https://www.youtube.com/watch?v=XLyDZ6RQYGI
#
# Author: Kevin Browne @ https://portfoliocourses.com
#
################################################################################
# Returns the area of a rectangle rounded to 4 decimal places for a length 'l'
# and a width 'w'
def rectangle_area(l,w):
return round(l * w, 4)
# Prompt the user to enter a length using input(), convert the string
# returned by input() to a float using float() and assign the result to
# length
length = float(input("Length: "))
# Do the same as the above for the rectangle's width
width = float(input("Width: "))
# Compute the area of a rectangle using the function rectangle_area()
area = rectangle_area(length,width)
# Output the computed area of the rectangle, prepended with the text "Area:"
print("Area:", area)