-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcircle_area.py
More file actions
30 lines (25 loc) · 1004 Bytes
/
circle_area.py
File metadata and controls
30 lines (25 loc) · 1004 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: Circle Area
#
# Description: Compute the area of a circle using Python.
#
# YouTube Lesson: https://www.youtube.com/watch?v=48yLHoaTwvo
#
# Author: Kevin Browne @ https://portfoliocourses.com
#
################################################################################
# Import the pi constant from the math library
from math import pi
# Define a function to compute the area of a circle, rounding the result to
# 4 decimal digits of accuracy
def circ_area(r):
return round(pi * r**2, 4)
# Prompt the user to enter a radius with input(), which returns a string,
# convert that string to a float with float() and assign the result to radius
radius = float(input("Radius: "))
# Use the circle area function to compute the radius
area = circ_area(radius)
# Output the resulting area, we convert the area value to a string with str()
# concatenate it to "Area: " with +
print("Area: " + str(area))