Sum=0.0
age1=int(raw_input("Enter person 1 age: "))
Sum+=age1
age2=int(raw_input("Enter person 2 age: "))
Sum+=age2
age3=int(raw_input("Enter person 3 age: "))
Sum+=age3
age4=int(raw_input("Enter person 4 age: "))
Sum+=age4
age5=int(raw_input("Enter person 5 age: "))
Sum+=age5
print "Average age = %g" %(Sum/5)
age=[int]*5 #integer array of size 5
Sum=0.0
for i in range(5):
print "Enter person", i+1, "age: ",
age[i]=int(raw_input())
for i in range(5):
Sum+=age[i]
print "Average age = %g" %(Sum/5)
flag=0
a=[float]*50
n=int(raw_input("Enter the size of a vector: "))
num=n
print "Enter the vector elements..."
for i in range(n):
print "a[", i, "] = ? ",
a[i]=int(raw_input())
for i in range(n-1):
for j in range(i+1, n):
if a[i]==a[j]:
n=n-1
for k in range(j, n):
a[k]=a[k+1]
flag=1
j=j-1
if flag:
print "vector has ", num-n, "duplicate elements=(s)."
print "Vector after removing duplicates..."
for i in range(n):
print "a[", i, "] = ", a[i]
else:
print "vector has no duplicate elements"
age=[float]*25
n=int(raw_input("How many persons are there in list <max-25>? "))
for i in range(n):
print "Enter person", i+1, "age: ",
age[i]=int(raw_input())
younger=age[0]
elder=age[0]
for i in range(n):
if age[i]<younger:
younger=age[i]
elif age[i]>elder:
elder=age[i]
print "Age of eldest person is", elder
print "Age of youngest person is: ", younger
age=[int]*25
n=int(raw_input("How many elements to sort <max-25>? "))
for i in range(n):
print "Enter age[", i, "]: ",
age[i]=int(raw_input())
for i in range(n-1):
flag=1
for j in range(n-1-i):
if age[j]>age[j+1]:
flag=0
temp=age[j]
age[j]=age[j+1]
age[j+1]=temp
if flag:
break
print "Sorted list..."
for i in range(n):
print age[i],
SHRINKINGFACTOR=1.3
age=[int]*25
n=int(raw_input("How many elements to sort <max-25>? "))
for i in range(n):
print "Enter age[", i, "]: ",
age[i]=int(raw_input())
size=n
gap=size
while 1:
gap=int(float(gap)/SHRINKINGFACTOR)
if gap==0:
gap=1
elif (gap==9 or gap==10):
gap=11
flag=1
top=size-gap
for i in range(top):
j=i+gap
if age[i]>age[j]:
flag=0
temp=age[j]
age[j]=age[i]
age[i]=temp
if(flag==1 and gap<=1):
break
print "Sorted list..."
for i in range(n):
print age[i],
a=[]
b=[]
c=[]
m, n=[int(x) for x in raw_input("Enter row and column size of matrix A: ").split()]
p, q=[int(x) for x in raw_input("Enter row and column size of matrix B: ").split()]
if(m==p and n==q):
print "Matrices can be added or subtracted..."
print "Enter matrix A elements..."
for i in range(m):
a.append([])
for j in range(n):
a[i].append(int(raw_input()))
print "Enter matrix B elements..."
for i in range(m):
b.append([])
for j in range(n):
b[i].append(int(raw_input()))
for i in range(m):
c.append([])
for j in range(n):
c[i].append(a[i][j]+b[i][j])
print "Sum of A and B matrices..."
for i in range(m):
for j in range(n):
print c[i][j],
print ""
for i in range(m):
for j in range(n):
c[i][j]=a[i][j]-b[i][j]
print "Difference of A and B matrices..."
for i in range(m):
for j in range(n):
print c[i][j],
print ""
name=[None]*50
name=raw_input("Enter your name <49-max>: ")
print "Your name is", name
msg="C to C++\nC++ to Java\nJava to..." #string with special characters
print "Please note the following messgae: "
print msg
s1=[None]*25
s1=raw_input("Enter your name: ")
print "strlen( s1 ) :", len(s1) #length of string
s1=[None]*25
s2=[None]*25
s1=raw_input("Enter a string: ")
s2=s1 #copying string
print "strcpy( s2, s1 ):", s2
s1=[None]*40
s2=[None]*25
s1=raw_input("Enter string s1: ")
s2=raw_input("Enter string s2: ")
s1=s1+s2 #concatenating string
print "strcat( s1, s2 ):", s1
s1=[None]*25
s2=[None]*25
s1=raw_input("Enter string s1: ")
s2=raw_input("Enter string s2: ")
print "strcmp( s1, s2 ):",
if s1==s2: #comparing strings
print s1, "is equal to", s2
elif s1>s2:
print s1, "is greater than", s2
else:
print s1, "is less than", s2
s1=[None]*25
temp=[None]*25
s1=raw_input("Enter a string: ")
temp=s1
print "strupr(temp):", temp.upper() #Upper case
print "strlwr(temp):", temp.lower() #lower case
person=[[None]*10]*LEN
n=int(raw_input("How many persons ? "))
for i in range(n):
print "Enter person", i+1, "name: ",
person[i]=raw_input()
print "------------------------------------------------------"
print "P# Person Name Length In lower case In UPPER case"
print "------------------------------------------------------"
for i in range(n):
print '{:>2}'.format(i+1),
print '{:>15}'.format(person[i]),
print '{:>2}'.format(len(person[i])),
print '{:>15}'.format(person[i].lower()),
print '{:>15}'.format(person[i].upper())
Str=["Anand", "Vishwanath", "Archana", "Yadunandan", "MalliKarjun"]
print 'The given strings are:'
for i in range(5):
print Str[i]
k=1
while k<5: #sorting strings
for i in range(1, 5-k+1):
if Str[i-1]>Str[i]:
str_temp=Str[i-1]
Str[i-1]=Str[i]
Str[i]=str_temp
k=k+1
print 'Strings in lexicographical order are:'
for i in range(5):
print Str[i]
Str="In pursuit of Mastering C++"
count=0
i=0
print "The given string is:\n",Str
while(i<len(Str)):
if Str[i]=='\t' or Str[i]==' ':
count+=1
i+=1
count+=1
print "The number of words given in the string is", count