0% found this document useful (0 votes)
90 views43 pages

Worksheet 1.3

This document contains: 1. An aims section outlining the goal of writing Python programs to calculate the area of circles and print multiplication tables using different function types. 2. An algorithm section explaining the steps to calculate circle areas using simple, parameterized, return type, and return type parameterized functions. It also explains how to print multiplication tables using the same four function types. 3. Code examples implementing the algorithms for each of the eight programs outlined.

Uploaded by

Abhishek Gorshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views43 pages

Worksheet 1.3

This document contains: 1. An aims section outlining the goal of writing Python programs to calculate the area of circles and print multiplication tables using different function types. 2. An algorithm section explaining the steps to calculate circle areas using simple, parameterized, return type, and return type parameterized functions. It also explains how to print multiplication tables using the same four function types. 3. Code examples implementing the algorithms for each of the eight programs outlined.

Uploaded by

Abhishek Gorshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 43

 

                                 

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.

Apparatus / Simulator Used:


Python IDE 
CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON
LAB
                                

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.

Return Type Function:


 Start the program.
 Create a user-defined function findarea().
 Enter the radius of circle from the user.
CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON
LAB
                                

 Take the value of pi as 22/7.


 Calculate the area using the formula: pi *radius*radius.
 Return type function is used to return the value.
 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.

Return Type 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.
 Return type function is used to return the value.
 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.

2. To print the multiplication tables from 2 to 20:

Simple Function:
 Start the program.
 Create a user-defined function multi.
 Print the table of 2 to 20 using for loop.
 Call the function.

CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON


LAB
                              

 End the program.


      
   Parameterized Function:
 Start the program.
 Create a user-defined function with the argument multi(num).
 Print the table of 2 to 20 using for loop.
 Call the function with arguments.
 End the program. 

Return Type Function: 


 Start the program.
 Create a user-defined function multi.
 Print the table of 2 to 20 using for loop.
 Return type function is used to return the value.
 Call the function.
 End the program. 

Return Type Parameterized Function: 


 Start the program.
 Create a user-defined function with arguments multi(num).
 Print the table of 2 to 20 using for loop.
 Return type function is used to return the value.
 Call the function with arguments.
 End the program. 

CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON


LAB

                              

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)

CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON


LAB

                              

Return Type Function:


#Return Type with 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 22/7 
    pi=22/7
#Calculate the area of circle 
    area= pi*a*a
#Print the area of the circle
    print("Area of the circle",area)
#Return the value 
    return area
    

#Accept the input of number of circles from the user


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

                              

Return Type Parameterized Function:


#Return Type with 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 22/7
    pi=22/7
#Calculate the area of circle 
    area= pi*a*a
#Print the area of the circle
    print("Area of the circle",area)
#Return the value
    return area

#Accept the input of number of circles from the user    


n=int(input("Enter number of circles to calculate the area:"))
for n in range(1,n+1):
#Call the function
    findarea(n)
CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON
LAB

                              

2. To print the multiplication tables from 2 to 20:

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

                              

#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)

Return Type Function:


#Return Type 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)
#Return the value
    return print("\n")
        
CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON
LAB

                              

for n in range(2,21):
    print("Table of ", n)
#Call the function
    multi()

Return Type Parameterized Function:


#Return Type 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)
    return print("\n")

for n in range(2,21):
    print("Table of",n)
#Call the function
    multi(n)

CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON


LAB

                              

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()
 

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)
 

CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON


LAB

                              

Return Type Function:


#Return Type with 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 22/7 
    pi=22/7
#Calculate the area of circle 
    area= pi*a*a
#Print the area of the circle
    print("Area of the circle",area)
#Return the value 
    return area
    
 
#Accept the input of number of circles from the user
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

                              

Return Type Parameterized Function:


#Return Type with 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 22/7
    pi=22/7
#Calculate the area of circle 
    area= pi*a*a
#Print the area of the circle
    print("Area of the circle",area)
#Return the value
    return area
 
#Accept the input of number of circles from the user    
n=int(input("Enter number of circles to calculate the area:"))
for n in range(1,n+1):
#Call the function
    findarea(n)

CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON


LAB

                              

2. To print the multiplication tables from 2 to 20

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()
 

CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON


LAB

                              

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

                              

Return Type Function: 


#Return Type 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)
#Return the value
    return print("\n")
        
        
for n in range(2,21):
    print("Table of ", n)
#Call the function
    multi()
 

CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON


LAB

                              

Return Type Parameterized Function:


 #Return Type 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)
    return print("\n")
 
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

                              

Return Type Parameterized Function:


CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON
LAB

                              

2. To print the tables from 2 to 20:


Simple 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

                              

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

                              

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

                              
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

                              
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.

CHANDIGARH UNIVERSITY                                    PROGRAMMING IN PYTHON


LAB

You might also like