letter='heavenly feeling'
letter=list(letter)
for count in letter:
print count.upper(),
Sum=0.0
List=[]
n=5
for count in range(0,n):
x=count+1
print "\ni = %d x = %d" %(count+1,x),
List.append(count)
Sum+=List[count]
avg=Sum/n
print "\n\nThe average is %5.2f\n\n" %avg
for count in range(0,n):
d=List[count]-avg
print "i=%d x=%5.2f d=%5.2f" %(count+1,List[count],d)
n=5
List=[3.0,-2.0,12.0,4.4,3.5]
Sum=0.0
for count in range(0,n):
Sum+=List[count]
avg=Sum/n
print "The average is %5.2f \n\n" %avg
for count in range(0,n):
d=List[count]-avg
print "i=%d x=%5.2f d=%5.2f\n" %(count+1,List[count],d)
def modify(a):
print "From the function after modifying the values: "
for count in range(0,3):
a[count]=-9
print "a[%d] = %d " %(count,a[count])
return
a=[]
print "From main, before calling the function: "
for count in range(0,3):
a.append(count+1)
print "a[%d] = %d " %(count,a[count])
modify(a)
print "From the main, after calling the function: "
for count in range(0,3):
print "a[%d] = %d " %(count,a[count])
a=1
def modify(b,c):
print "From the function, after modifying the value : "
global a
a=-999
b=-999
print "a = %d b = %d" %(a,b)
for count in range(0,3):
c[count]=-9
print "c[%d] = %d" %(count,c[count])
return
b=2
c=[]
print "From main, before calling the function: "
print "a = %d b = %d" %(a,b)
for count in range(0,3):
c.append(10*(count+1))
print "c[%d] = %d" %(count,c[count])
modify(b,c)
print "From main, after calling the function:"
print "a = %d b = %d" %(a,b)
for count in range(0,3):
print "c[%d] = %d" %(count,c[count])
def reorder(n,x):
for item in range(0,n-1):
for i in range(item+1,n):
if x[i]<x[item]:
temp=x[item]
x[item]=x[i]
x[i]=temp
return
x=[]
n=10
print
for i in range(0,n):
inp=i+1
print "\ni = %d x = %d" %(i+1,inp),
x.append(inp)
reorder(n,x)
print "\n\nReordered list of numbers: \n"
for i in range(0,n):
print "i = %d x = %d" %(i+1,x[i])
def countwords(english):
words=1
for count in range(0,len(english)-1):
if english[count]==' ' and english[count+1]!=' ':
words+=1
return words
def convert(words,english,piglatin):
m1=0
for n in range(1,words+1):
count=m1
while english[count]!=' ':
m2=count
count+=1
for count in range(m1,m2):
piglatin.append(english[count+1])
piglatin.append(english[m1])
piglatin.append('a')
piglatin.append(' ')
m1=m2+2
return
def writeoutput(piglatin):
piglatin=''.join(piglatin)
print piglatin
return
def main(english):
english=list(english)
piglatin=[]
english.append(' ')
words=countwords(english)
convert(words,english,piglatin)
writeoutput(piglatin)
return
print '\nC is a popular structured programming language'
main('C is a popular structured programming language')
print '\nbaseball is the great American pastime.'
main('baseball is the great American pastime.')
print '\nthough there are many who prefer football'
main('though there are many who prefer football')
print '\nplease do not sneeza in the computer room'
main('please do not sneeza in the computer room')
def readinput(m,n,i=0):
at=[]
for row in range(0,m):
temp=[]
for col in range(0,n):
t=i
i+=1
temp.append(t)
at.append(temp)
return at
def computesum(a,b,m,n):
c=[]
for row in range(0,m):
temp=[]
for col in range(0,n):
t=a[row][col]+b[row][col]
temp.append(t)
c.append(temp)
return c
def writeoutput(c,m,n):
for row in range(0,m):
for col in range(0,n):
print "%4d" %(c[row][col]),
print
return
print "\n FIRST TABLE : \n"
a=readinput(5,5,1)
writeoutput(a,5,5)
print "\n SECOND TABLE : \n"
b=readinput(5,5,50)
writeoutput(b,5,5)
c=computesum(a,b,5,5)
print "Sums of the elements : \n"
writeoutput(c,5,5)