Page 286 - CTS - CSA TP - Volume 2
P. 286
COMPUTER SOFTWARE APPLICATION - CITS
TASK 2: Calculate the area of different shapes
# File: geometry.py
import math
defcalculate_square_area(side):
return side * side
defcalculate_rectangle_area(length, width):
return length * width
defcalculate_circle_area(radius):
returnmath.pi * radius * radius
# File: geometry_program.py
import geometry
# Calculate areas using functions from the geometry module
square_area = geometry.calculate_square_area(5)
rectangle_area = geometry.calculate_rectangle_area(6, 4)
circle_area = geometry.calculate_circle_area(3)
# Print the calculated areas
print(“Area of square:”, square_area)
print(“Area of rectangle:”, rectangle_area)
print(“Area of circle:”, circle_area)
Output:
TASK 3: Simple Arithmetic Operator
Code:
# my_module.py
defadd(x, y):
returnx+y
defsubtract(x, y):
returnx-y
defmultiply(x, y):
returnx*y
defdivide(x, y):
ify!=0:
returnx/y
else:
271
CITS : IT & ITES - Computer Software Application - Exercise 130