import sys
#Variable Initialization
n = int(raw_input("\nHow many integers ? "))
x = [0 for i in range(0,n)]
for i in range(0,n):
x[i] = int(raw_input("\nEnter the %dth value : "%(i+1)))
#Processing
#sum is a predefined function in python. so sum1 is used
sum1 = 0
for i in range(0,n):
sum1 = sum1 + x[i]
#Output
sys.stdout.write("\nSum of all integers = %d"%(sum1))
import sys
#Variable initialization
n = int(raw_input("\nHow many numbers ? "))
sys.stdout.write("\nEnter all those numbers ")
x = [0 for i in range(0,n)]
for i in range(0,n):
x[i] = int(raw_input(""))
#Processing
big = x[0]
for i in range(0,n):
if x[i] > big:
big = x[i]
#Output
sys.stdout.write("\n%d is the biggest number"%(big))
import sys
import math
#Variable Initialization
n = int(raw_input("\nHow many values ? "))
x = [0.0 for i in range(0,n)]
sys.stdout.write("\nEnter all values in the list\n")
for i in range(0,n):
x[i] = float(raw_input(""))
#Processing
sum1 = 0
#Since sum is a predefined function in python, sum1 is used
for i in range(0,n):
sum1 = sum1 + x[i]
xbar = sum1 / n
vsum = 0
for i in range(0,n):
vsum = vsum + (x[i] - xbar) * (x[i] - xbar)
sigmax = vsum / n
sd = math.sqrt(sigmax)
#Output
sys.stdout.write("\nArithmetic mean = %0.3f"%(xbar))
sys.stdout.write("\nVariance = %0.3f"%(sigmax))
sys.stdout.write("\nStandard deviation = %0.3f"%(sd))
import sys
#Variable Initialization
n = int(raw_input("\nHow many students ? "))
sys.stdout.write("\nEnter all the marks \n")
for i in range(0,n):
x[i] = int(raw_input(""))
#Processing
sum1 = 0.0
#Since sum is a predefined function in python, sum1 is used
for i in range(0,n):
sum1 = sum1 + x[i]
mean = float(sum1/n)
#Output
sys.stdout.write("\nMean = %6.2f"%(mean))
sys.stdout.write("\n\nMarks greater than mean : ")
for i in range(0,n):
if x[i] > mean:
sys.stdout.write("%5d"%(x[i]))
import sys
import math
#Variable Initialization
n = int(raw_input("\nHow many values ? "))
sys.stdout.write("\nEnter all values in the list \n")
for i in range(0,n):
x[i] = float(raw_input(""))
psum = 0
nsum = 0
#Processing
for i in range(0,n):
if x[i] > 0:
psum = psum + x[i]
else:
nsum = nsum + x[i]
#Output
sys.stdout.write("\nSum of positive values = %0.2f"%(psum))
sys.stdout.write("\nSum of negative values = %0.2f"%(nsum))
if psum > math.fabs(nsum):
sys.stdout.write("\nPositive sum is greater in magnitude")
else:
sys.stdout.write("\nNegative sum is greater in magnitude")
diff = math.fabs(psum - math.fabs(nsum))
sys.stdout.write("\nDifference in magnitude = %0.2f"%(diff))
import sys
#Variable Initialization
n = int(raw_input("How many numbers ? "))
sys.stdout.write("\nEnter the list of %d numbers\n"%(n))
for i in range(0,n):
x[i] = int(raw_input(""))
#Processing
for i in range(0,n):
for j in range(i+1,n):
if x[i] > x[j]:
temp = x[i]
x[i] = x[j]
x[j] = temp
#Output
sys.stdout.write("\nNumbers in ascending order\n")
for i in range(0,n):
sys.stdout.write("%5d"%(x[i]))
import sys
x = [0 for i in range(0,50)]
#Variable Initialization
n = int(raw_input("\nHow many values in the list ? "))
sys.stdout.write("\nEnter all values in the list\n")
for i in range(0,n):
x[i] = int(raw_input(""))
s = int(raw_input("\nEnter the key value to be searched : "))
#Processing
for i in range(0,n):
if s == x[i]:
sys.stdout.write("\n%d is available in %dth location"%(s,i+1))
if i == n+1:
sys.stdout.write("\nThe key value %d is not present in the list"%(s))
import sys
#Variable Initialization
exchng = 0
n = int(raw_input("\nHow many numbers ? "))
sys.stdout.write("\nEnter all numbers in the list\n")
for i in range(0,n):
x[i] = int(raw_input(""))
#Processing
for i in range(0,n-1):
for j in range(0,n-i-1):
if x[j] > x[j+1]:
temp = x[j]
x[j] = x[j+1]
x[j+1] = temp
exchng = exchng + 1
#Output
sys.stdout.write("\nThe sorted list is\n")
for i in range(0,n):
sys.stdout.write("%5d"%(x[i]))
sys.stdout.write("\nSorted in %d passes and %d exchanges"%(n-1,exchng))
import sys
#Variable declaration and initialization
m = int(raw_input("\nHow many rows and columns ? "))
n = int(raw_input(""))
a = [[0 for i in range(0,m)] for j in range(0,n)]
b = [[0 for i in range(0,m)] for j in range(0,n)]
c = [[0 for i in range(0,m)] for j in range(0,n)]
sys.stdout.write("\nEnter A matrix\n")
for i in range(0,m):
for j in range(0,n):
a[i][j] = int(raw_input(""))
sys.stdout.write("\nEnter B matrix\n")
for i in range(0,m):
for j in range(0,n):
b[i][j] = int(raw_input(""))
#Processing
for i in range(0,m):
for j in range(0,n):
c[i][j] = a[i][j] + b[i][j]
#Output
sys.stdout.write("\nResultant matrix is \n")
for i in range(0,m):
for j in range(0,n):
sys.stdout.write("%6d"%(c[i][j]))
sys.stdout.write("\n")
import sys
#Variable declaration and initialization
m = int(raw_input("\nEnter order of A matrix : "))
n = int(raw_input(""))
a = [[0 for i in range(0,m)] for j in range(0,n)]
b = [[0 for i in range(0,m)] for j in range(0,n)]
c = [[0 for i in range(0,m)] for j in range(0,n)]
sys.stdout.write("\nEnter A matrix\n")
for i in range(0,m):
for j in range(0,n):
a[i][j] = int(raw_input(""))
n = int(raw_input("\nEnter order of B matrix : "))
l = int(raw_input(""))
sys.stdout.write("\nEnter B matrix\n")
for i in range(0,n):
for j in range(0,l):
b[i][j] = int(raw_input(""))
#Processing
for i in range(0,n):
for j in range(0,l):
c[i][j] = 0
for k in range(0,n):
c[i][j] = c[i][j] + a[i][k] * b[k][j]
#Output
sys.stdout.write("\nResultant matrix is \n")
for i in range(0,m):
for j in range(0,l):
sys.stdout.write("%6d"%(c[i][j]))
sys.stdout.write("\n")
import sys
#Variable declaration and initialization
m = int(raw_input("\nEnter order of the matrix : "))
n = int(raw_input(""))
a = [[0 for i in range(0,10)] for j in range(0,10)]
at = [[0 for i in range(0,10)] for j in range(0,10)]
sys.stdout.write("\nEnter the matrix values\n")
for i in range(0,m):
for j in range(0,n):
a[i][j] = int(raw_input(""))
#Processing
for i in range(0,m):
for j in range(0,n):
at[j][i] = a[i][j]
#Output
sys.stdout.write("\nThe transposed matrix is\n")
for i in range(0,n):
for j in range(0,m):
sys.stdout.write("%6d"%(at[i][j]))
sys.stdout.write("\n")
import sys
#Variable declaration and initialization
m = int(raw_input("\nEnter order of the square matrix : "))
a = [[0 for i in range(0,10)] for j in range(0,10)]
sys.stdout.write("\nEnter the matrix\n")
for i in range(0,m):
for j in range(0,m):
a[i][j] = int(raw_input(""))
#Processing
flag = 0
for i in range(0,m):
if flag == 0:
for j in range(0,m):
if flag == 0:
if a[i][j] == a[j][i]:
continue
else:
flag = 1
#Output
if flag == 0:
sys.stdout.write("\nThe given matrix is a symmetric matrix")
else:
sys.stdout.write("\nThe given matrix is not a symmetric matrix")
import sys
#Variable declaration and initialization
m = int(raw_input("\nEnter order of the square matrix : "))
a = [[0 for i in range(0,10)] for j in range(0,10)]
sys.stdout.write("\nEnter the matrix\n")
for i in range(0,m):
for j in range(0,m):
a[i][j] = int(raw_input(""))
#Processing
sum1 = 0
#since sum is a predefined function in python, sum1 is used
for i in range(0,m):
sum1 = sum1 + a[i][i]
#Output
sys.stdout.write("\nTrace of the matrix = %d"%(sum1))