sum = 0
a1 = int(raw_input("Age:"))
sum += a1
a2 = int(raw_input("Age:"))
sum += a2
a3 = int(raw_input("Age:"))
sum += a3
a4 = int(raw_input("Age:"))
sum += a4
a5 = int(raw_input("Age:"))
sum += a5
print "The ages that were input are:"
print a1
print a2
print a3
print a4
print a5
print "Average = %d" %(sum/5)
sum = 0.0
age = []
n = int(raw_input("Number of persons:"))
if n<=0 or n>5:
print "Invalid number of person entered"
else:
for i in range(n):
age.append(int(raw_input("Age :")))
sum += age[i]
print "The ages input are:"
for i in range (n):
print age[i]
print "The average is :",(sum/n)
a = []
n = int(raw_input("Size of vector ? "))
print "Vector elements ? "
for i in range (n):
a.append(float(raw_input()))
large = max(a)
small = min(a)
print "Largest element in vector is %8.2f" %large
print "Smallest element in vector is %8.2f" %small
a = []
n = int(raw_input("Size of vector ? "))
print "Vector elements ? "
for i in range (n):
a.append(float(raw_input()))
for i in range (n-1):
for j in range(i+1,n):
if a[i]> a[j]:
a[i],a[j]=a[j],a[i]
print "Vector elements in ascending order :"
for i in range(n):
print "%8.2f" %a[i]
a = []
n = int(raw_input("Size of vector ? "))
print "Vector elements ? "
for i in range (n):
a.append(float(raw_input()))
item = float(raw_input("Element to be inserted ?"))
pos = int(raw_input("Position of insertion ?"))
a.insert(pos-1, item)
print "Vector after insertion"
for ele in a:
print ele,
rollno = 4
subject = 3
def display(studentmarks):
for r in range(rollno):
print "\nRoll no.: ", r+1,
for s in range(subject):
print "%10.2f" %studentmarks[r][s],
marks =[[35.5, 40.5, 45.5],
[50.5, 55.5, 60.5],
[65.0, 70.0, 75.5],
[80.0, 85.0, 90.0]]
display(marks)
import numpy
a = numpy.zeros((10, 10))
b = numpy.zeros((10, 10))
c = numpy.zeros((10, 10))
print "Input row & column of A matrix: "
n = int(raw_input("row: "))
m = int(raw_input("column: "))
print "Input row & column of B matrix: "
p = int(raw_input("row: "))
q = int(raw_input("column: "))
if n == p and m == q:
print "Matrices can be added"
print "Input A matrix: ",
for i in range(n):
for j in range(m):
a[i][j] = int(raw_input())
print ""
print "Input B matrix: ",
for i in range(p):
for j in range(q):
b[i][j] = int(raw_input())
print ""
for i in range(p):
for j in range(q):
c[i][j] = a[i][j] + b[i][j]
print "Sum of A & B matrices: "
for i in range(n):
for j in range(m):
print "%5d" %c[i][j],
print ""
else:
print "Matricess cannot be added"
import numpy
a = numpy.zeros((10, 10))
print "Enter the order of A matrix: ",
n = int(raw_input())
print "Input A matrix"
for i in range(n):
for j in range(n):
a[i][j] = int(raw_input())
trace = 0
for i in range(n):
trace += a[i][i]
print "Trace = ", trace
import numpy
def read_mat(a, m, n):
for i in range(m):
for j in range(n):
a[i][j] = int(raw_input())
def write_mat(a, m, n):
for i in range(m):
for j in range(n):
print "%d" %a[i][j],
print ""
a = numpy.zeros((10, 10))
b = numpy.zeros((10, 10))
c = numpy.zeros((10, 10))
print "Input row & column of A matrix: "
n = int(raw_input("row: "))
m = int(raw_input("column: "))
print "Input row & column of b matrix: "
k = int(raw_input("row: "))
q = int(raw_input("column: "))
if n == k:
print "Matrices can be multiplied"
print "Resultant Matrix is %d x %d" %(m, q)
print "Input A matrix"
read_mat(a, m, n)
print "Input B matrix"
read_mat(b, k, q)
for i in range(m):
for j in range(q):
c[i][j] = 0
for ip in range(n):
c[i][j] = c[i][j]+a[i][ip]*b[ip][j]
print "Resultant of A and B matrices: "
write_mat(c, m, q)
else:
print "col of matrix A must be equal to row of matrix B"
print "Matrices cannot be multiplied"
import numpy
a = numpy.zeros((10, 10))
print "Input row & column of A matrix: "
n = int(raw_input("row: "))
m = int(raw_input("column: "))
print "Input A matrix: "
for i in range(n):
for j in range(m):
a[i][j] = int(raw_input())
print "Transpose of matrix A is"
for i in range(m):
for j in range(n):
print "%5d" %a[j][i],
print ""
strc = "This is a string literal"
print strc
names = ["Tejaswi",
"Prasad",
"Prasanth",
"Prakash",
"Anand",]
for name in names:
print name
oneString = "Fish"
twoString = "face"
oneString += twoString
print oneString
a = []
print "Size of vector ?"
n = int(raw_input())
num = n
print "Vector Elements ?"
for i in range(n):
a.append(float(raw_input()))
a = set(a)
a = list(a)
length = len(a)
print length
if length == n:
print "No duplicates found"
else:
print "Vector has %d duplicates" %(num - length)
print "Vector after deleting duplicates: ",
for ele in a:
print ele,
import numpy
grade = ['', '', '', '', '', '', '', '', '', '', '', '', '', '']
a = numpy.zeros((50,10))
print "Number of students ?",
n = int(raw_input())
for i in range(n):
sum = 0.0
print "Enter 3 socres of student %d" %(i+1)
for j in range(3):
a[i][j] = (float(raw_input()))
sum += a[i][j]
avg = sum/3
a[i][3] = avg
if avg < 30.0:
grade[i] = 'E'
elif avg < 60.0:
grade[i] = 'D'
elif avg < 75.0:
grade[i] = 'B'
else:
grade[i] = 'A'
print "S1.no scores AVERAGE GRADE"
print "---------------------------------------------"
for i in range(n):
print i+1,
for j in range(4):
print "%8.2f" %a[i][j],
print "%6c" %grade[i],
print ""
print "---------------------------------------------"
import math
sumsq = 0
sum = 0
print "Calculation standard deviation of a"
print "Enter size of the list: ",
n = int(raw_input())
x = []
print "Enter the %d items " %n
for i in range(n):
x.append(float(raw_input()))
sum += x[i]
mean = sum/n
for i in range(n):
sumsq = sumsq + (mean-x[i]) * (mean-x[i])
variance = sumsq/n
sdn = math.sqrt(variance)
print "Mean of %5d items : %10.6f" %(n, mean)
print "Variance : %10.6f" %(variance)
print "Standard Deviation : %10.6f" %sdn
import numpy
import math
def nrm(a, n, m):
sum = 0.0
for i in range(n):
for j in range(m):
sum = sum + a[i][j] * a[i][j]
print "Sum = %6.2f" %sum
return math.sqrt(sum)
a = numpy.zeros((10, 10))
print "Input row & column of A matrix"
n = int(raw_input("row: "))
m = int(raw_input("column: "))
print "Input A matrix"
for i in range(n):
for j in range(m):
a[i][j] = float(raw_input())
norm = nrm(a, n, m)
print "Norm = %6.2f" %norm
import numpy
a = numpy.zeros((5, 5))
flag = True
print "Input size of matrix"
n = int(raw_input("row: "))
m = int(raw_input("column: "))
print "Enter the elements of the matrix: "
for i in range(m):
for j in range(n):
a[i][j] = float(raw_input())
for i in range(m):
min = a[i][0]
p = i
q = 0
for j in range(n):
if min > a[i][j]:
min = a[i][j]
p = i
q = j
for j in range(m):
if j != q:
if a[j][q] > a[p][q]:
flag = False
if flag:
print "Saddle point a[%d][%d] = %d" %(p+1, q+1, a[p][q])
else:
print "No saddle is in row %d" %(i+1)
flag = True
import numpy
a = numpy.zeros((10, 10))
b = numpy.zeros((10, 10))
flag = None
print "Input order of A matrix"
n = int(raw_input("row: "))
print "Input A matrix"
for i in range(n):
for j in range(n):
a[i][j] = int(raw_input())
for i in range(n):
for j in range(n):
b[i][j] = a[j][i]
print "Transpose of A matrix"
for i in range(n):
for j in range(n):
print "%5d" %b[i][j],
print ""
for i in range(n):
for j in range(n):
if a[i][j] != b[i][j]:
flag = True
if flag:
print "Matrix is not symmetric"
else:
print "Matrix is symmetric"