Name=[None]*25
Name=raw_input("Enter name of the 1st person: ")
Salary=float(raw_input("Enter Salary: "))
if(Salary<=90000):
Tax=Salary*12.5/100
else:
Tax=Salary*18/100
print "The tax amount for", Name, "is:", Tax
Name=raw_input("Enter name of the 2nd person: ")
Salary=float(raw_input("Enter Salary: "))
if(Salary<=90000):
Tax=Salary*12.5/100
else:
Tax=Salary*18/100
print "The tax amount for", Name, "is:", Tax
def CalculateTax(): #function for calculating tax
Name=[None]*25
Name=raw_input("Enter name of the person: ")
Salary=float(raw_input("Enter Salary: "))
if(Salary<=90000):
Tax=Salary*12.5/100
else:
Tax=Salary*18/100
print "The tax amount for", Name, "is:", Tax
CalculateTax()
CalculateTax()
def Max(x,y):
if x>y:
return x
else:
return y
a, b=[int(x) for x in raw_input("Enter two integers <a,b>: ").split()]
c=Max(a,b)
print "max (a, b):", c
def Max(x,y):
if x>y:
return x
else:
return y
a, b=[int(x) for x in raw_input("Enter two integers <a,b>: ").split()]
c=Max(a,b)
print "max (a, b):", c
import sys
def PercentageChart(percentage):
for i in range(percentage/2):
sys.stdout.write('\x3d')
print "Sridevi : ",
PercentageChart(50)
print "\nRajkumar: ",
PercentageChart(84)
print "\nSavithri: ",
PercentageChart(79)
print "\nAnand : ",
PercentageChart(74)
import sys
def PercentageChart(percentage):
for i in range(percentage/2):
sys.stdout.write('\x3d')
m1, m2, m3, m4=[int(x) for x in raw_input("Enter percentage score of Sri, Raj, Savi, An: ").split()]
print "Sridevi : ",
PercentageChart(m1)
print "\nRajkumar: ",
PercentageChart(m2)
print "\nSavithri: ",
PercentageChart(m3)
print "\nAnand : ",
PercentageChart(m4)
import sys
def PercentageChart(percentage, style):
for i in range(percentage/2):
sys.stdout.write(style)
m1, m2, m3, m4=[int(x) for x in raw_input("Enter percentage score of Sri, Raj, Savi, An: ").split()]
print "Sridevi : ",
PercentageChart(m1, '*')
print "\nRajkumar: ",
PercentageChart(m2, '\x3D')
print "\nSavithri: ",
PercentageChart(m3, '-')
print "\nAnand : ",
PercentageChart(m4, '!')
def fact(n):
if n==0:
result=1
else:
result=1
for i in range(2, n+1):
result*=i
return result
n=int(raw_input("Enter the number whose factorial is to be found: "))
print "The factorial of", n, "is", fact(n)
name=[None]*20
name=raw_input("Enter your name: ")
Len=len(name) #string length
print "Length of your name =", Len
import math
num=float(raw_input("Enter any factorial number: "))
num1=math.ceil(num) #ceiling of number
num2=math.floor(num) #floor of number
print "ceil(",num,") =", num1
print "floor(",num,") =", num2
def swap(x, y): #pass by value swap
print "Value of x and y in swap before exchange:", x, y
t=x
x=y
y=t
print "Value of x and y in swap after exchange:", x, y
a, b=[int(x) for x in raw_input("Enter two integers <a,b>: ").split()]
swap(a,b)
print "Value of a and b on swap a, b) in main():", a, b
def swap(x, y): #pass by address swap
t=x
x=y
y=t
return x, y
a, b=[int(x) for x in raw_input("Enter two integers <a ,b>: ").split()]
a, b = swap(a, b)
print "Value of a and b on swap( a, b ):", a, b
def swap(x, y): #pass by reference swap
t=x
x=y
y=t
return x, y
a, b=[int(x) for x in raw_input("Enter two integers <a,b>: ").split()]
a, b = swap(a, b)
print "Value of a and b on swap( a, b):", a, b
def Max(x,y):
if x>y:
return x
else:
return y
a, b=[int(x) for x in raw_input("Enter two integers <a, b>: ").split()]
if Max(a,b)==a:
a=425
else:
b=425
print "The value of a and b on execution of mx(x, y)=425;..."
print "a =", a, "b =", b
import sys
def PrintLine(ch='-', RepeatCount=70): #default arguments
for i in range(RepeatCount):
sys.stdout.write(ch)
print ''
PrintLine()
PrintLine('!')
PrintLine('*', 40)
PrintLine('R', 55)
import sys
def PrintLine(ch='-', RepeatCount=70, nLines=1): #default arguments
for i in range(nLines):
for i in range(RepeatCount):
sys.stdout.write(ch)
print ''
PrintLine()
PrintLine('!')
PrintLine('*', 40)
PrintLine('R', 55)
PrintLine('&', 25, 2)
def sqr(num):
return num*num
n=float(raw_input("Enter a number: "))
print "Its square =",sqr(n)
print "sqr( 10 ) =", sqr(10)
#different swap functions
def swap_char(x, y):
t=x
x=y
y=t
return x, y
def swap_int(x, y):
t=x
x=y
y=t
return x, y
def swap_float(x, y):
t=x
x=y
y=t
return x, y
ch1, ch2=[str(x) for x in raw_input("Enter two characters <ch1, ch2>: ").split()]
ch1, ch2 = swap_char(ch1, ch2)
print "On swapping <ch1, ch2>:", ch1, ch2
a, b=[int(x) for x in raw_input("Enter two characters <a, b>: ").split()]
a, b = swap_int(a, b)
print "On swapping <a, b>:", a,b
c, d=[float(x) for x in raw_input("Enter two floats <c, d>: ").split()]
c, d = swap_float(c, d)
print "On swapping <c, d>:", c, d
def swap(x, y): #function overloading
t=x
x=y
y=t
return x, y
ch1, ch2=[str(x) for x in raw_input("Enter two characters <ch1, ch2>: ").split()]
ch1, ch2 = swap(ch1, ch2)
print "On swapping <ch1, ch2>:", ch1, ch2
a, b=[int(x) for x in raw_input("Enter two characters <a, b>: ").split()]
a, b = swap(a, b)
print "On swapping <a, b>:", a,b
c, d=[float(x) for x in raw_input("Enter two floats <c, d>: ").split()]
c, d = swap(c, d)
print "On swapping <c, d>:", c, d
def show(val): #function overloading
if(isinstance(val, int)):
print "Integer:", val
if(isinstance(val, float)):
print "Double:", val
if(isinstance(val, str)):
print "String:", val
show(420)
show(3.1415)
show("Hello World!")
def swap(x, y):
t=x
x=y
y=t
return x, y
ch1, ch2=[str(x) for x in raw_input("Enter two characters <ch1, ch2>: ").split()]
ch1, ch2 = swap(ch1, ch2)
print "On swapping <ch1, ch2>:", ch1, ch2
a, b=[int(x) for x in raw_input("Enter two characters <a, b>: ").split()]
a, b = swap(a, b)
print "On swapping <a, b>:", a,b
c, d=[float(x) for x in raw_input("Enter two floats <c, d>: ").split()]
c, d = swap(c, d)
print "On swapping <c, d>:", c, d
(false, true)=(0, 1) #enum type
type =['false', 'true']
def swap(x, y):
x, y=y, x
return x, y
def BubbleSort(a, size):
swapped='true'
for i in range(size-1):
if swapped:
swapped='false'
for j in range((size-1)-i):
if a[j]>a[j+1]:
swapped='true'
a[j], a[j+1]=swap(a[j], a[j+1])
return a
a=[int]*25
print "Program to sort elements..."
size=int(raw_input("Enter the size of the integer vector <max-25>: "))
print "Enter the elements of the integer vector..."
for i in range(size):
a[i]=int(raw_input())
a=BubbleSort(a, size)
print "Sorted Vector:"
for i in range(size):
print a[i],
def linear(arr, num):
for i in range(10):
if arr[i]==num:
return i
return -1
a=[10, 20, 5, 59, 63, 22, 18, 99, 11, 65] # 1-D array
element=int(raw_input("Enter the element to be searched: "))
result=linear(a, element)
if result==-1:
print element, "is not present in the array"
else:
print element, "is present at",result, "location in the array"
def Func(j, k):
print "In the function the argument values are", j, "..", k
i=99
Func(i+1, i)
g=100
def func1():
g=50
print "Local variable g in func1() :", g
def func2():
global g
print "In func2() g is visible since it is global."
print "Incremeting g in func..."
g+=1
print "In main g is visible here since g is global."
print "Assigning 20 to g in main..."
g=20
print "Calling func1..."
func1()
print "func1 returned. g is", g
print "Calling func2..."
func2()
print "func2 returned. g is", g
import sys
i=int
name=raw_input("Enter a string: ")
print "The reverse of the string is: ",
for i in range(len(name)-1, -1, -1):
sys.stdout.write(name[i])
def PrintCount(Count=[1]):
print 'Count =', Count[0]
Count[0]=Count[0]+1
PrintCount()
PrintCount()
PrintCount()
def add(*argc):#variable number of arguments to the function
result=0
for i in range(1, argc[0]+1):
result+=argc[i]
return result
sum1=add(3, 1, 2, 3)
print "sum1 =", sum1
sum2=add(1, 10)
print "sum2 =", sum2
sum3=add(0)
print "sum3 =", sum3
def sum(*msg): #variable number of arguments to the function
total=0
i=1
while(msg[i]!=0):
total+=msg[i]
i+=1
print msg[0], total
sum("The total of 1+2+3+4 is", 1, 2, 3, 4, 0)
def fact(num): #recursive function
if num==0:
return 1
else:
return num*fact(num-1)
n=int(raw_input("Enter the number whose factorial is to be found: "))
print "The factorial of", n, "is", fact(n)
def hanoi(n, left, mid, right): #recursive function
if n!=0:
hanoi(n-1, left, right, mid)
print 'Move disk', n, 'from', left, 'to', right
hanoi(n-1, mid, left, right)
source='L'
intermediate='C'
destination='R'
nvalue=int(raw_input('Enter number of disks: '))
hanoi(nvalue, source, intermediate, destination)
def power(x1, y1=None):
if (isinstance(y1, int)):
result=1.0
for i in range(1, y1+1):
result=result*x1
return result
else:
return x1*x1
x=float(raw_input("Enter the value of x: "))
y=int(raw_input("Enter the value of y: "))
print "power(x, y) =", power(x, y)
print "power(x) =", power(x)