def message(): #function definition
print "Smile,and the world smiles with you...\n"
message() #function call
print "Cry, and you stop the monotony!\n"
def italy():
print "I am in italy\n"
def brazil():
print "I am in brazil\n"
def argentina():
print "I am in argentina\n"
print "I am in main\n"
italy(); #italy() will be called
brazil(); #brazil() will be called
argentina(); #argentina() will be called
def italy():
print "I am in italy\n"
brazil(); #it will call brazil()
print "I am back in italy\n"
def brazil():
print "I am in brazil\n"
argentina(); #it will call argentina()
def argentina():
print "I am in argentina\n"
print "I am in main\n"
italy(); #italy() is called
print "I am finally back in main\n"
def message():
print "Can't imagine life without C\n"
main() #it will call back main()
def main():
message()
main()
def message():
print "Jewel Thief!!\n"
message() #1st call
message() #2nd call
def message2():
print "But the butter was bitter\n"
def message1():
print "Mary bought some butter\n"
message1()
message2()
def calsum(x,y,z): #parameterized function
d=x+y+z
return d
print "Enter any three numbers"
a=eval(raw_input())
b=eval(raw_input())
c=eval(raw_input())
sum=calsum(a,b,c) #passing values as arguments
print "Sum=%d\n" % (sum)
def fun():
print "Enter any number"
n=eval(raw_input())
if (n>=10 and n<=90):
return n
else:
return n+32
fun()
def fun(b):
b=60
print "%d\n" % (b) #prints 60
a=30
fun(a) #prints 30
print "%d\n" % (a)
def display(j):
k=35
print "%d\n" % (j) #we can't print i directly here because scope of variable is local by default
print "%d\n" % (k)
i=20
display(i)
def square(x):
y=x*x
return y
print "Enter any number"
a=eval(raw_input())
b=square(a)
print "Square of %f is %f\n" % (a,b)
i=3
print "Address of i=%u\n" % (id(i)) #id() will return the loaction of a variable
print "Value of i=%d\n" % (i)
i=3
print "Address of i=%u\n" % (id(i))
print "Value of i=%d\n" % (i)
print "Value of i=%d\n" % (i)
i=3
j=id(i)
print "Address of i=%u\n" % (id(i)) #print address of i
print "Address of i=%u\n" % (j) #print address of i
print "Address of j=%u\n" % (id(j)) #print address of j
print "Value of j=%u\n" % (j) #print value of j
print "Value of i=%d\n" % (i)
print "Value of i=%d\n" % (i)
print "Value of i=%d\n" % (i)
i=3
j=id(i)
k=id(j)
print "Address of i=%u\n" % (id(i)) #print address of i
print "Address of i=%u\n" % (j) #print address of i
print "Address of i=%u\n" % (j) #print address of i
print "Address of j=%u\n" % (id(j)) #print address of i
print "Address of j=%u\n" % (k) #print address of j
print "Address of k=%u\n" % (id(k)) #print address of k
print "Value of j=%u\n" % (j) #print value of j
print "Value of k=%u\n" % (k) #print value of k
print "Value of i=%u\n" % (i) #print value of i
print "Value of i=%u\n" % (i)
print "Value of i=%u\n" % (i)
print "Value of i=%u\n" % (i)
def swapv(x,y):
x,y=y,x
print "x=%d y=%d\n" % (x,y)
a=10
b=20
swapv(a,b)
print "a=%d b=%d\n" % (a,b)
def swapr():
global a,b #global declaration
a,b=b,a
a=10
b=20
swapr()
print "a=%d b=%d\n" % (a,b)
def areaperi(r,a,p):
a=3.14*r*r #formula of area
p=2*3.14*r #formula of perimeter
print "Area=%f\n" % (a)
print "Perimeter=%f\n" % (p)
area=0
perimeter=0
print "Enter radius of a circle"
radius=eval(raw_input())
areaperi(radius,area,perimeter)
def factorial(x):
f=1
for i in range(x,1,-1):
f=f*i
return f
print "Enter any number"
a=eval(raw_input())
fact=factorial(a)
print "Factorial value=%d\n" % (fact)
def rec(x):
if x==1:
return 1
else:
f=x*rec(x-1)
return f #will call back the rec() function
print "Enter any number"
a=eval(raw_input())
fact=rec(a)
print "Factorial value=%d\n" % (fact)
def add(i,j):
sum=i+j
return sum
a=5
b=2
c=add(a,b) #Transfers control to add()
print "sum=%d\n" % (c)
def factorial(num):
f=1
for i in range(1,num+1,1):
f=f*i;
return f
f=factorial(5)
print "%d\n" % f