bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_2 / python / sec_3.py

sec_3.py (1382B)


      1 # Function to calculate area of a circle
      2 def area_circle():
      3     radius = float(input("Enter the radius of the circle: "))
      4     area = 3.14 * radius * radius
      5     print(f"Area of the Circle = {area:.2f}")
      6 
      7 # Function to calculate area of a rectangle
      8 def area_rectangle():
      9     length = float(input("Enter the length of the rectangle: "))
     10     breadth = float(input("Enter the breadth of the rectangle: "))
     11     area = length * breadth
     12     print(f"Area of the Rectangle = {area:.2f}")
     13 
     14 # Function to calculate area of a triangle
     15 def area_triangle():
     16     base = float(input("Enter the base of the triangle: "))
     17     height = float(input("Enter the height of the triangle: "))
     18     area = 0.5 * base * height
     19     print(f"Area of the Triangle = {area:.2f}")
     20 
     21 # Main menu function
     22 def menu():
     23     while True:
     24         print("\n--- Area Calculator ---")
     25         print("1. Area of Circle")
     26         print("2. Area of Rectangle")
     27         print("3. Area of Triangle")
     28         print("4. Exit")
     29         choice = input("Enter your choice (1-4): ")
     30         if choice == '1':
     31             area_circle()
     32         elif choice == '2':
     33             area_rectangle()
     34         elif choice == '3':
     35             area_triangle()
     36         elif choice == '4':
     37             print("Exiting the program...")
     38             break
     39         else:
     40             print("Invalid choice! Please try again.")
     41 
     42 # Call the menu function
     43 menu()