0% found this document useful (0 votes)
33 views7 pages

Python 1.3 KushagrJain

The document is a worksheet submitted by a student for their Programming in Python lab course. It contains programs demonstrating different types of functions in Python including simple functions, parameterized functions, functions with return types, and functions with default arguments. The programs calculate circle areas and multiplication tables to illustrate the various function concepts. Screenshots of the program outputs are provided as requested in the worksheet.

Uploaded by

KUSHnot2OP
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)
33 views7 pages

Python 1.3 KushagrJain

The document is a worksheet submitted by a student for their Programming in Python lab course. It contains programs demonstrating different types of functions in Python including simple functions, parameterized functions, functions with return types, and functions with default arguments. The programs calculate circle areas and multiplication tables to illustrate the various function concepts. Screenshots of the program outputs are provided as requested in the worksheet.

Uploaded by

KUSHnot2OP
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/ 7

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

WORKSHEET 1.3
Student Name: Kushagr Jain UID: 21BCS1877
Branch: BE-CSE Section/Group: 615 - B
Semester: 4th Date of Performance: 20-02-2023
Subject Name: Programming in Python Lab Subject Code: 21-CSP-259

1. Aim: Writing python program for various type of functions and with return type.

2. Source Code:
A) 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 function.

pi = 22/7 def
circleArea1(): x = 2
print("area of circle 1=
",pi*x*x)
def circleArea2(x):
print("area of circle 2=
",pi*x*x)
def
circleArea3():
x = 4 area =
pi*x*x return
area
def
circleArea4(x):
area = pi*x*x
return area
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
def circleArea5(): x = 6
print("area of circle 5=
",pi*x*x)
def circleArea6(x):
print("area of circle 6=
",pi*x*x)
def
circleArea7(): x
=8

area = pi*x*x
return area
def circleArea8(x):
area = pi*x*x
return area
def circleArea9(): x = 5
print("area of circle 9=
",pi*x*x)
def circleArea10(x):
print("area of circle 10=
",pi*x*x)
circleArea1() circleArea2(3)
print("Area of circle
3:",circleArea3()) print("Area of
circle 4:",circleArea4(5))
circleArea5() circleArea6(7)
print("Area of circle
7:",circleArea7()) print("Area of
circle 8:",circleArea8(9))
circleArea9()
circleArea10(11)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
B) 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 function.

def tables1(): num = 5 for


i in range(1,11):
print(num,'x', i,
'=',num*i)
print("\n")
def tables2(num):
for i in range(1,11):
print(num,'x', i,
'=',num*i)
print("\n")
def tables3(): num = 7 for
i in range(1,11):
print(num,'x', i,
'=',num*i) print("\n")

return 0
def tables4(num):
for i in range(1,11):
print(num,'x', i, '=',num*i)
return 0
print(tables1())
print(tables2(6
))
print(tables3())
print(tables4(8
))
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

3. Screenshot of Outputs:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
3) Program to demonstrate the use of functions

def greet():
print('21BCS1877')

# call the function


greet()

print('This is Worksheet 3')

ScreenShot:

4) Program to demonstrate the use of return statement in functions.

def add(a, b):


return a + b
print("21BCS1877"+"\nKushagr Jain")
res = add(2, 3)
print("Result of add function is {}".format(res))

ScreenShot:
5) Program to demonstrate the passing of arguments in functions.

def add_numbers( a = 7, b = 8):


sum = a + b
print('Sum:', sum)

# function call with two arguments


add_numbers(2, 3)

# function call with one argument


add_numbers(a = 2)

# function call with no arguments


add_numbers()

ScreenShot:

6) Program to demonstrate the use of Default Arguments in functions.

def student(firstname, lastname ='Jain', standard ='Fifth'):


print(firstname, lastname, 'studies in', standard, 'Standard')

# 1 positional argument
student('Rohit')

# 3 positional arguments
student('Rohit', 'Jain', 'Seventh')

# 2 positional arguments
student('Kushagr', 'Jain')
student('', 'Joe')

ScreenShot:

You might also like