-
Notifications
You must be signed in to change notification settings - Fork 0
/
area_perimeter_calculator.py
56 lines (42 loc) · 1.53 KB
/
area_perimeter_calculator.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
46
47
48
49
50
51
52
53
54
55
56
import math
def main():
print("Welcome to the Area and Perimeter Calculator!")
while True:
print("\nChoose a shape:")
print("1. Rectangle")
print("2. Square")
print("3. Circle")
print("4. Exit")
choice = input("Enter your choice (1/2/3/4): ")
if choice == '1':
calculate_rectangle()
elif choice == '2':
calculate_square()
elif choice == '3':
calculate_circle()
elif choice == '4':
print("Thank you for using the calculator. Goodbye!")
break
else:
print("Invalid choice. Please enter a valid option.")
def calculate_rectangle():
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
area = length * width
perimeter = 2 * (length + width)
print(f"Area of the rectangle: {area}")
print(f"Perimeter of the rectangle: {perimeter}")
def calculate_square():
side = float(input("Enter the side length of the square: "))
area = side * side
perimeter = 4 * side
print(f"Area of the square: {area}")
print(f"Perimeter of the square: {perimeter}")
def calculate_circle():
radius = float(input("Enter the radius of the circle: "))
area = math.pi * radius**2
circumference = 2 * math.pi * radius
print(f"Area of the circle: {area}")
print(f"Circumference of the circle: {circumference}")
if __name__ == "__main__":
main()