forked from portfoliocourses/python-example-code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsquare_perimeter.py
More file actions
28 lines (24 loc) · 1.02 KB
/
square_perimeter.py
File metadata and controls
28 lines (24 loc) · 1.02 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
################################################################################
#
# Program: Perimeter of a Square
#
# Description: Compute the perimeter of a square using Python.
#
# YouTube Lesson: https://www.youtube.com/watch?v=T_h7SR4U57Y
#
# Author: Kevin Browne @ https://portfoliocourses.com
#
################################################################################
# Returns the perimeter of a square rounded to 2 decimal places for a given side
# length 'l'
def square_perimeter(l):
return round(l * 4, 2)
# Prompt the user to enter a side length using input(), convert the string
# returned by input() to a float using float() and assign the result to
# side_length
side_length = float(input("Side Length: "))
# Compute the perimeter of a square using the function square_perimeter()
perimeter = square_perimeter(side_length)
# Output the square perimeter, use str() to convert the perimeter numeric value
# to a string and concatenate that string to "Perimeter: " with +
print("Perimeter: " + str(perimeter))