def product(x,y): #function product
return x*y
a=input('Please input a number: ') #user input
b=input('Please input another number: ')
c=product(a,b)
print 'the product of ',a,'and',b,'is',c
def product(x,y): #function product
return x*y
a=input('Please input a floating point number: ') #user input
b=input('Please input another floating point number: ')
c=product(a,b) #function call
print 'the product of ',a,'and',b,'is',c
def printProduct(x,y): #function product
c=0
c=a*b
print 'The product of ',a,'and',b,'is',c
return
a=input('Please input an intger: ') #user input
b=input('Please input another integer: ')
c=printProduct(a,b)
def product(x,y): #function product
return x*y
a=input('Please input a number: ') #user input
b=input('Please input another number: ')
c=product(a,b)
print 'the product of ',a,'and',b,'is',c
from ctypes import c_int,pointer
i =c_int(4)
j=i
pi=pointer(i)
value=pi[0]
pj=pi[0]
print 'Before incrementing *pi'
print 'i= ',i.value,'j= ',j.value,'*pi= ',pi[0],'*pj= ',pj
pi[0]+=1 #no prefix and postfix in python
pj=pi[0]
print 'After incrementing *pi'
print 'i= ',i.value,'j= ',j.value,'*pi= ',pi[0],'*pj= ',pj
def Product(x,y): #function product
return x*y
print 'Please input two integer: ' #user input
a=input()
b=input()
c=Product(a,b) #call function product
print 'The product of ',a,'and',b,'is',c
print 'Please input two floating point numbers: '
f=input()
g=input()
h=Product(f,g) #call function product
print 'The product of ',f,'and',g,'is',h
def fracval(numerator =0, denominator =1): #function declaration with default parameters
val=(numerator/denominator)
return val
print 'please input numerator and denominator of a fraction: '
a=input()
b=input()
f=fracval(a,b) #function call
print 'The fraction value ',a,'/',b,'=',f
print 'please input the numerator (denominator assumed to be 1: )'
a=input()
f=fracval(a)
print 'The fraction value ',a,'/1','=',f
print 'And the defaukt fraction value is (num=0, denom=1): '
f=fracval()
print 'the fraction value 0/1=',f
def swap(a,b):
temp=a
a=b
b=temp
#variable declaration
x=3
y=4
print 'before swap: x= ',x,'y= ',y
swap(x,y)
print 'After swap: x= ',x,'y= ',y
def swap(a,b): #function swap
temp = a
a = b
b = temp
return a,b
#variable declaration
x=3
y=4
print 'before swap: x= ',x,'y= ',y
x,y=swap(x,y)
print 'After swap: x= ',x,'y= ',y
def swap(a,b): #function swap
temp = a
a = b
b = temp
return a,b
#variable declaration
x=3
y=4
print 'before swap: x= ',x,'y= ',y
x,y=swap(x,y)
print 'After swap: x= ',x,'y= ',y
def PrintCharManyTimes(ch,n): #function declarator
for j in range(n): #function body
print ch,
print
PrintCharManyTimes('-',40) #call to function
print 'Data type Range'
PrintCharManyTimes('=',18) #call to function
print 'Char -128 to 127'
print 'int -32,768 to 32,767'
print 'double -2,147,483,648 to 2,147,483,647'
PrintCharManyTimes('-',40) #call to function
def factfunc(a): #calls itself to calculate factorials
if a>1:
return a * factfunc(a-1)
else:
return 1
n = input("Please input a number: ") #get number from user
fact = factfunc(n) #function call for factorial
print 'Factorial of',n,'! is',fact,'\n' #dsplay factorial
gi=1 #global variable declared
si = 1 #static variable declared
def func():
global si
i=1
i+=1
si+=1
global gi
gi+=1
print 'i= ',i,'si= ',si,'gi= ',gi
for i in range(10):
print '(',i,')Call to func(): ',
gi+=1
func()
def max(x,y): #function defined
if x>y:
return x
else:
return y
a=5
b=6
c=max(a,b)
if c==a: # no return by refernce function so declared a simple case
c=8
a=c
elif c==b:
c=8
b=c
print 'a=',a,'b=',b,'c=',c
def op1(v): #for displaying numbers
for j in range(len(v)):
print v[j],
def remove_if(v,x): #for removing elements
for a in v:
if not a%x==0:
v.remove(a)
return v
nos=[10,12,15,20,25,27]
print '(before): ',;op1(nos)
x=5
print ''
nos=remove_if(nos,5)
print '(after): ',;op1(nos)
def sort(number): #for sorting
size=len(number)
for i in range(size-1 ):
if int(number[i])>int(number[i+1]):
temp=number[i]
number[i]=number[i+1]
number[i+1]=temp
return number
def op1(v): #for displaying numbers
for j in range(len(v)):
print v[j],
number=["1","12","23","2"]
print '(original): ',;op1(number)
print ''
number=sort(number) # 1st sort
print '(after 1st sort): ',;op1(number)
print ''
number=sort(number)
print '(after 2nd sort): ',;op1(number) # 2nd sort
print ''