0% found this document useful (0 votes)
3 views

python 5

Uploaded by

mediamccewin
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)
3 views

python 5

Uploaded by

mediamccewin
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/ 3

5. Programs related to functions & modules .

# Function with arguments


Name:-Pranav Sanjay Badhe Div:-
A
Roll no:- 08 Date:-
Batch no:- B1

def fun_hello(name):
message="Hello "+name
return(message)

name=input("Enter your name ")


print(fun_hello(name))

#Output
Enter your name: Student
Hello Student

#Keyword argument

def sum(a,b,c):
return(a+b+c)
print("Sum is",sum(b=3,a=7,c=10))

#Output
Sum is 20

#Default argument

def welcome(str,address="Dhanaji Nana


Mahavidyalaya,Faizpur"):
print("I am a ",str,"of ",address)

welcome(name="student")

#Output
I am a student of Dhanaji Nana Mahavidyalaya,Faizpur

#Variable length argument

def vararg(*names):
print("Type of argument passed
is",type(names)) print("The arguments
passed are") for name in names:
print(name)

vararg("C","C++","Python")

#Output
Type of arguments passed is <class 'tuple'>
The arguments passed are
C
C++
Python

#Function with multiple return value

def getdimensions():
length=float(input("Enter The
Length :-")) width=float(input("Enter
The Width :-")) return length,width
l,w=getdimensions()
print(l,w)

#Output
Enter The Length :-10
Enter The Width :-20
10.0 20.0

#Recursive function

def product(a,b):
if(a<b):
return product(b,a)
elif(b!=0):
return(a+product(a,b-1))
else: return 0
a=int(input("Enter first number:
")) b=int(input("Enter second
number: "))
print("Product is: ",product(a,b))

#Output
Enter first number: 12
Enter second number: 4
Product is: 48

#User defined modules

def sq(n):
print("Square is", n*n)

import square
square.sq(5)

#Output
Square is 25

#Program to use math module

import math
math.log10(10)
print(math.log10(10))
math.pow(2,3)
print(math.pow(2,3))
math.sqrt(100)
print(math.sqrt(100))
math.ceil(4.4875)
print(math.ceil(4.4875))
math.floor(5.6875)
print(math.floor(5.6875))

#Output
1.0
8.0
10.0

You might also like