python 5
python 5
def fun_hello(name):
message="Hello "+name
return(message)
#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
welcome(name="student")
#Output
I am a student of Dhanaji Nana Mahavidyalaya,Faizpur
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
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
def sq(n):
print("Square is", n*n)
import square
square.sq(5)
#Output
Square is 25
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