# function definition
def message():
print "Smile, and the world smiles with you..."
message() #function call
print "Cry, and you stop the monotony!"
# function definitions
def italy():
print "I am in italy"
def brazil():
print "I am in brazil"
def argentina():
print "I am in argentina"
print "I am in main"
#function calls
italy()
brazil()
argentina()
# function definitions
def argentina():
print "I am in argentina"
def brazil():
print "I am in brazil"
argentina() #function call
def italy():
print "I am in italy"
brazil() #function call
print "I am back in italy"
print "I am in main"
#function call
italy()
print "I am finally back in main"
# function definition
def calsum ( x, y, z ):
d = x + y + z
return d
#Input from user
#a,b,c = raw_input ("Enter any three numbers: ").split()
print "Enter any three numbers: "
a = 10
b = 20
c = 30
print a,b,c
#function call
s = calsum(a,b,c)
#Result
print "Sum = ", s
# function definition
def fun():
#Input from user
#ch = raw_input ("Enter any alphabet: ")
print "Enter any alphabet: "
ch = 'a'
print ch
ch = ord(ch)
if ch >= 65 and ch <= 90:
return ascii(ch)
else:
return ascii( ch + 32 )
#function call
ch = fun()
#Result
print ch
# function definition
def fun(b):
b = 60
print b
a = 30
fun(a) #function call
print a
# function definition
def display(j):
k = 35
print j
print k
i = 20
display(i) #function call
# function definition
def square(x):
y = x * x
return y
#Input from user
#a = raw_input("Enter any number: ")
print "Enter any number: "
a = 4.5
print a
b = square(a) #function call
#Result
print "Square of %f is %f" %( a, b )
# function definition
def gospel(): # void function
print "Viruses are electronic bandits..."
print "who eat nuggets of information..."
print "and chunks of bytes..."
print "when you least expect..."
gospel() # function call
#Variable declaration
i = 3
#Result
print "Address of i = " , id(i) #printing address
print "Value of i = ", i
#Variable declaration
i = 3
j = id(i) # address of variable 'i'
#Result
print "Address of i = ", id(i)
print "Address of i = ", j
print "Address of j = ", id(j)
print "Value of j = ", j
print "Value of i = ", i
print "Value of i = ", i
print "Value of i = ", i
#Variable declaration
i = 3
j = id(i) # address of i
k = id(j) # address of j
#Result
print "Address of i = ", id(i)
print "Address of i = ", j
print "Address of i = ", j
print "Address of j = ", id(j)
print "Address of j = ", k
print "Address of k = ", id(k)
print "Value of j = ", j
print "Value of k = ", k
print "Value of i = ", i
print "Value of i = ", i
print "Value of i = ", i
print "Value of i = ", i
# function definition
def swapv (x,y):
x,y=y,x
print "x = %d y = %d" %( x, y )
#Variable declaration
a = 10
b = 20
swapv ( a, b ) # function call
#Result
print "a = %d b = %d" %( a, b )
# function definition
def swapv (a,b):
a,b=b,a
return a,b
#Variable declaration
a = 10
b = 20
a,b = swapv ( a, b ) # function call
#Result
print "a = %d b = %d" %( a, b )
print "Enter radius of a circle: "
radius = 5
print radius
#Function definition
def areaperi ( r ):
a = 3.14 * r * r
p = 2 * 3.14 * r
return a,p
area,perimeter = areaperi ( radius ) #function call
#Result
print "Area = ", area
print "Perimeter = ", perimeter
# function definition
def factorial(x):
f = 1
for i in range(x,0,-1 ):
f = f * i
return f
print "Enter any number: "
a = 6
print a
fact = factorial(a) #function call
#Result
print "Factorial value = ", fact
# function definition
def rec(x):
if x == 1:
return 1
else:
f = x * rec ( x - 1 ) # calling the function
return f
print "Enter any number: "
a = 5
print a
fact = rec(a) #function call
#Result
print "Factorial value = ", fact
#Variable declaration
a = 5
b = 2
#Function definition
def add ( i, j ):
s = i + j
return s
c = add ( a, b ) # function call
#Result
print "sum = ", c