Worksheet 1.3
Worksheet 1.3
WORKSHEET – 1.3
Name: Abhishek
Section/Group: 719 / “A”
UID: 20BCS7643
Subject: Programming in Python Lab
Date of Submission: 04.3.2022
Branch: BE CSE (4 Semester)
th
Aim:
Write a python code that will developing programming concepts using all
functions of the Python.
Task to be done:
1. Write a python program to calculate area of 10 different circles. Given
the pie = 22/7 and radius of the circles entered by user using Simple
Function, Parameterized Function, Return Type with function and return
type with parameterized Functions.
2. Write a python program to print Multiplication tables from 2 to 20
whether table values entered by user using Simple Function,
Parameterized Function, Return Type with function and return type with
parameterized Functions.
Algorithm / Flowchart:
1. To calculate area of 10 different circles:
Simple Function:
Start the program.
Create a user-defined function findarea().
Enter the radius of circle from the user.
Take the value of pi as 22/7.
Calculate the area using the formula: pi *radius*radius.
Call the function by entering the number of circles of which area
you want to calculate.
Print all the values with a suitable message.
End the program.
Parameterized Function:
Start the program.
Create a user-defined function with the arguments
findarea(radius).
Enter the radius of circle from the user.
Take the value of pi as 22/7.
Calculate the area using the formula: pi *radius*radius.
Call the function with the arguments by entering the number of
circles of which area you want to calculate.
Print all the values with a suitable message.
End the program.
Simple Function:
Start the program.
Create a user-defined function multi.
Print the table of 2 to 20 using for loop.
Call the function.
Code:
1. To calculate area of 10 different circles:
Simple Function:
#Simple Function Program to calculate area of 10 different circles. Given the
pie = 22/7 and radius of the circles entered by user
#Create a user-defined function
def findarea():
#Accept the input from the user for radius of the circle
a=int(input("Enter radius of circle:"))
#Value of pi
pi=22/7
#Calculate the area of circle
area= pi*a*a
#Print the area of circle
print("Area of the circle",area)
#Accept the input from user to print the area of how many circles
n=int(input("Enter number of circles to calculate the area:"))
for n in range(1,n+1):
#Call the function
findarea()
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
Parameterized Function:
#Parameterized Function Program to calculate area of 10 different circles.
Given the pie = 22/7 and radius of the circles entered by user
#Create a user defined function
def findarea(radius):
#Accept the input from the user for radius of the circle
a=int(input("Enter radius of circle:"))
#Value of pi
pi=22/7
#Calculate the area of circle
area= pi*a*a
#Print the area of the circle
print("Area of the circle",area)
#Accept the input from user to print the area of how many circles
n=int(input("Enter number of circles to calculate the area:"))
for n in range(1,n+1):
#Call the function
findarea(n)
Simple Function:
#Simple Function Program to print Multiplication tables from 2 to 20
whether table values entered by user
#Create a user defined function
def multi():
#Print the table of range 2 to 20
for i in range(1,11):
a=n*i
print(n,' x ', i, ' = ',a)
for n in range(2,21):
print("Table of ", n)
#Call the function
multi()
Parameterized Function:
#Parameterized Function Program to print Multiplication tables from 2 to 20
whether table values entered by user
#Create a user defined function
def multi(num):
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
for n in range(2,21):
print("Table of ", n)
#Call the function
multi(n)
for n in range(2,21):
print("Table of ", n)
#Call the function
multi()
for n in range(2,21):
print("Table of",n)
#Call the function
multi(n)
Screenshots:
1. To calculate area of 10 different circles:
Simple Function:
#Simple Function Program to calculate area of 10 different circles. Given the
pie = 22/7 and radius of the circles entered by user
#Create a user-defined function
def findarea():
#Accept the input from the user for radius of the circle
a=int(input("Enter radius of circle:"))
#Value of pi
pi=22/7
#Calculate the area of circle
area= pi*a*a
#Print the area of circle
print("Area of the circle",area)
#Accept the input from user to print the area of how many circles
n=int(input("Enter number of circles to calculate the area:"))
for n in range(1,n+1):
#Call the function
findarea()
Parameterized Function:
#Parameterized Function Program to calculate area of 10 different circles.
Given the pie = 22/7 and radius of the circles entered by user
#Create a user defined function
def findarea(radius):
#Accept the input from the user for radius of the circle
a=int(input("Enter radius of circle:"))
#Value of pi
pi=22/7
#Calculate the area of circle
area= pi*a*a
#Print the area of the circle
print("Area of the circle",area)
#Accept the input from user to print the area of how many circles
n=int(input("Enter number of circles to calculate the area:"))
for n in range(1,n+1):
#Call the function
findarea(n)
Simple Function:
#Simple Function Program to print Multiplication tables from 2 to 20 whether
table values entered by user
#Create a user defined function
def multi():
#Print the table of range 2 to 20
for i in range(1,11):
a=n*i
print(n,' x ', i, ' = ',a)
for n in range(2,21):
print("Table of ", n)
#Call the function
multi()
Parameterized Function:
#Parameterized Function Program to print Multiplication tables from 2 to 20
whether table values entered by user
#Create a user defined function
def multi(num):
#Print the table of range 2 to 20
for i in range(1,11):
a=n*i
print(n,' x ', i, ' = ',a)
for n in range(2,21):
print("Table of ", n)
#Call the function
multi(n)
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
Result / Output:
1. To calculate area of 10 different circles:
Simple Function:
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
Parameterized Function:
Return Type Function:
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
Parameterized Function:
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
Return Type Parameterized Function:
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
CHANDIGARH UNIVERSITY PROGRAMMING IN PYTHON
LAB
Learning Outcomes:
1. Learn how to implement all the functions in python
2. Learn about return and without return functions concept.
3. Learn about arguments.
4. Learn about difference between simple and parameterized function.
5. Learn how to write code in python, about indentation.