forked from portfoliocourses/python-example-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectangle_perimeter.py
More file actions
31 lines (26 loc) · 1.05 KB
/
rectangle_perimeter.py
File metadata and controls
31 lines (26 loc) · 1.05 KB
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
31
################################################################################
#
# Program: Rectangle Perimeter
#
# Description: Compute the perimeter of a rectangle using Python.
#
# YouTube Lesson: https://www.youtube.com/watch?v=Jxu8O1NOzpw
#
# Author: Kevin Browne @ https://portfoliocourses.com
#
################################################################################
# Returns the perimeter of a rectangle rounded to 4 decimal places for a length
# 'l' and a width 'w'
def rectangle_perimeter(l,w):
return round(2 * (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 perimeter of a rectangle using the function rectangle_perimeter()
perimeter = rectangle_perimeter(length,width)
# Output the computed perimeter of the rectangle, prepended with the text
# "Perimeter:"
print("Perimeter:", perimeter)