DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
WORKSHEET 1.3
Student Name: Aman Singh Aswal UID: 21BCS3399
Branch: CSE Section/Group: 611 A
Date of Performance: 28th Feb Semester: 4th
Subject Name: Programming in Python Lab Subject Code: 21CSP-259
1. Aim:
i) Write a python program to calculate the area of 10 different circle given
the pie = 22/7 and radius of the circles entered by the user using simple
function, parameterized function, return type with function and return
type with parameterized function.
ii) Write a python program to print multiplication tables from 2 to 20 where
tables values are entered by the user by using simple function,
parameterizes function, return type with function and return type with
parameterized function
2. Source Code:
1st Program
pie = 22/7
def circle_area(radius):
""" this function will calculate the area of the circle using
simple function appraoch """
area = pie * radius ** 2
return area
def circle_area_with_parameter(radius, pie):
""" this function will calculate the area of the circle using
parameterized function"""
area = pie * radius ** 2
return area
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
def circle_area_return(radius):
""" this function will calculate the area of the circle using
return type with function"""
return pie * radius **2
def circle_area_return_with_parameter(radius, pie):
""" this function will calculate the area of the circle using
return type with parameterized function"""
return pie * radius ** 2
# program to calculate the area of the circle
for i in range(1,11):
radius = eval(input(f"Enter the radius of the circle {i}: "))
#simple function approach
area1 = circle_area(radius)
print(f"Area of the circle {i} (simple function):
{area1:.2f}")
# Parameterized function approach
area2 = circle_area_with_parameter(radius, pie)
print(f"Area of circle {i} (parameterized function):
{area2:.2f}")
# Return type with function approach
area3 = circle_area_return(radius)
print(f"Area of circle {i} (return type with function):
{area3:.2f}")
# Return type with parameterized function approach
area4 = circle_area_return_with_parameter(radius, pie)
print(f"Area of circle {i} (return type with parameterized
function): {area4:.2f}")
print() # Print a blank line for spacing
Program 2nd
# simple function
def multiplication_table_simple(table_values):
"""multiplication table using simple function"""
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
for i in range(1, 11):
print(table_values, 'x', i, '=', table_values*i)
print(multiplication_table_simple.__doc__)
table_values = int(input("Enter the table values: "))
multiplication_table_simple(table_values)
# paremeterized function
def multiplication_table_paremeterized(start, end):
"""multiplication table using paremeterized function"""
print(multiplication_table_paremeterized.__doc__)
table_values = int(input("Enter the table values between 2 and 20:
"))
print('Multiplication table of ', table_values, ':')
for i in range(start, end+1):
print(table_values, 'x', i, '=', table_values*i)
print()
multiplication_table_paremeterized(1, 10)
# return type function
def multiplication_table(n):
"""multiplication table using return type function"""
table = []
for i in range(1, 11):
table.append(n*i)
return table
print(multiplication_table.__doc__)
table_values = int(input("Enter the table values to multiply: "))
print('Multiplication table of', table_values, ':')
print(multiplication_table(table_values))
print()
# return type with parameterized function
def multiplication_table(start, end):
tables = []
for i in range(2, 21):
table = []
for j in range(start, end+1):
table.append(i*j)
tables.append(table)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
return tables
result = multiplication_table(1, 10)
for i, table in enumerate(result, start=2):
print('Multiplication table of', i, ':')
print(table)
print()
3. Screenshot of Outputs:
Output of 1st Program
Output of 2nd Program
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING