-
Notifications
You must be signed in to change notification settings - Fork 1
/
circlelator.py
45 lines (37 loc) · 1.21 KB
/
circlelator.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Getting the maths stuff used for sqrt() and pi
import math
# Defining Pi
pi = math.pi
# Getting input
known_element = raw_input('What do you know about the circle? ').lower()
known_value = raw_input('How much is %s? ' % (known_element))
known_value = float(known_value)
# If diameter is entered
if known_element == 'diameter' or known_element == 'd':
diameter = known_value
radius = diameter/2
circumference = pi * diameter
area = pi * float(radius) ** 2
# If radius is entered
if known_element == 'radius' or known_element == 'r':
radius = known_value
diameter = radius * 2
circumference = pi * float(diameter)
area = pi * float(radius) ** 2
# If circumference is entered
if known_element == 'circumference' or known_element == 'c':
circumference = known_value
diameter = circumference / pi
radius = diameter / 2
area = pi * float(radius) ** 2
# If area is entered
if known_element == 'area' or known_element == 'a':
area = known_value
radius = math.sqrt(area) / math.sqrt(pi)
diameter = radius * 2
circumference = pi * float(diameter)
# Printing results
print "The diameter is %s" % (diameter)
print "The circumference is %s" % (circumference)
print "The radius is %s" % (radius)
print "The area is %s" % (area)