from array import *
# Variable declaration
a = [[1,2,3,4,5],
[6,7,8,9,10],
[11,12,13,14,15],
[16,17,18,19,20],
[21,22,23,24,25]]
# Calculation and result
print ('The value of a is %x ' % id(a))
for i in range (0, 5) :
print ('The value of a[%d] is %x ' % (i, id(i)))
for i in range (0, 5) :
for j in range (0, 5) :
print ('The cell [%d][%d] i.e. %x has %d ' % (i, j, id(a[i][j]), a[i][j]))
from array import *
# Variable declaration
a = [[[1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15], [16,17,18,19,20]],
[[21,22,23,24,25], [26,27,28,29,30], [31,32,33,34,35], [36,37,38,39,40]]]
# Calculation and result
print ('The value of a is %x ' % id(a))
for i in range (0, 2) :
print ('The value of a[%d] is %x ' % (i, id(a[i])))
for j in range (0, 4) :
print ('The value of a[%d][%d] is %x ' % (i, j, id(a[i][j])))
print
for i in range (0, 2) :
for j in range (0, 4) :
for k in range (0, 5) :
print ('The cell [%d][%d][%d] i.e. %x has %d ' % (i, j, k, id(a[i][j][k]), a[i][j][k]))
# Function declaration, calculation and result
def readdata (a, num) :
while num > 0 :
a[num-1] = int(raw_input('Enter value in cell[%d] ' % num))
num = num - 1
def printdata (a, num) :
while num > 0 :
print ('Value in cell[%d] is %d ' % (num, a[num-1]))
num = num - 1
n = int(raw_input('Enter the number of elements '))
a = [0 for i in xrange(n)]
readdata (a, n)
print
printdata (a, n)
# Function declaration, calculation and result
def readdata (a, n) :
while n > 0 :
a[n-1] = int(raw_input('Enter value in cell[%d] ' % n))
n = n - 1
def printdata (a, n) :
while n > 0 :
print ('Value in cell[%d] is %d ' % (n, a[n-1]))
n = n - 1
n = int(raw_input('Enter the number of elements '))
a = [0 for i in xrange(n)]
readdata (a, n)
print
printdata (a, n)
# Function declaration, calculation and result
global n
n = 0
def makearray (n) :
n = int(raw_input('Enter the number of elements '))
return n
def readdata (a, n) :
while n > 0 :
a[n-1] = int(raw_input('Enter value in cell[%d] ' % n))
n = n - 1
def printdata (a, n) :
while n > 0 :
print ('Value in cell[%d] is %d ' % (n, a[n-1]))
n = n - 1
n = makearray (n)
a = [0 for i in xrange(n)]
readdata (a, n)
print
printdata (a, n)
# Variable declaration, calculation and result
string = raw_input('Enter the string: ')
rev_string = reversed(string)
if list(string) == list(rev_string) :
print ('%s is a PALINDROME ' % string)
else :
print ('%s is not a PALINDROME ' % string)
# Function declaration, calculation and result
def readdata (a, n) :
for i in range (0, n) :
a[i] = int(raw_input('Enter data in cell [%d] ' % i))
return a
def bubble (a, n) :
for p in range (0, n) :
for i in range (0, n-1-p) :
if a[i] > a[i+1] :
temp = a[i]
a[i] = a[i+1]
a[i+1] = temp
return a
def printdata (a, n) :
for i in range (0, n) :
print ('The data in cell [%d] is %d ' % (i, a[i]))
n = int(raw_input('Enter the number of elements to be entered: '))
a = [0] * n
a = readdata (a, n)
a = bubble (a, n)
print ('\nThe sorted data is ')
printdata (a, n)
# Variable declaration, calculation and result
i = 6
c = 'a'
the_data = i
print ('the_data points to the integer value %d ' % the_data)
the_data = c
print ('the_data points to the character value %c ' % the_data)
# Variable declaration
marks = [[0 for x in xrange(5)] for x in xrange(5)]
avg = 0
percent = [0 for x in xrange(5)]
# Function declaration, calculation and result
def readncompute (marks, percent, avg) :
no_of_students = int(raw_input('How many students marks do you want to enter? '))
for i in range (0, no_of_students) :
print ('\nEnter marks of 5 subjects for roll no. %d ' % (i+1))
for j in range (0, 5) :
marks[i][j] = int(raw_input('Subject %d: ' % (j+1)))
percent[i] = percent[i] + marks[i][j]
percent[i] = percent[i]/5
avg = avg + percent[i]
return avg/no_of_students, no_of_students
def printdata (score, per, avg, no_of_students) :
for i in range (0, no_of_students) :
print ('\nMarks for roll no. %d are ' % (i+1))
for j in range (0, 5) :
print ('%d ' % score[i][j])
print ('Percentage for roll no. is %.2f ' % per[i])
if per[i] < avg :
print ('Below average')
else :
print ('Above average')
average, nos = readncompute(marks, percent, avg)
print ('\nThe average marks are %.2f' % average)
printdata (marks, percent, average, nos)
# Variable declaration
marks = [[0 for x in xrange(5)] for x in xrange(5)]
avg = 0
percent = [0 for x in xrange(5)]
# Function declaration, calculation and result
def readncompute (marks, percent, avg) :
no_of_students = int(raw_input('How many students marks do you want to enter? '))
for i in range (0, no_of_students) :
print ('\nEnter marks of 5 subjects for roll no. %d ' % (i+1))
for j in range (0, 5) :
marks[i][j] = int(raw_input('Subject %d: ' % (j+1)))
percent[i] = percent[i] + marks[i][j]
percent[i] = percent[i]/5
avg = avg + percent[i]
return avg/no_of_students, no_of_students
def printdata (score, per, avg, no_of_students) :
for i in range (0, no_of_students) :
print ('\nMarks for roll no. %d are ' % (i+1))
for j in range (0, 5) :
print ('%d ' % score[i][j])
print ('Percentage for roll no. is %.2f ' % per[i])
if per[i] < avg :
print ('Below average')
else :
print ('Above average')
average, nos = readncompute(marks, percent, avg)
print ('\nThe average marks are %.2f' % average)
printdata (marks, percent, average, nos)
# Function declaration, calculation and result
def readdata (a, n) :
for i in range (0, n) :
a[i] = int(raw_input('Enter data in cell [%d] ' % i))
return a
def bubble (name) :
for p in range (0, 4) :
for i in range (0, 3-p) :
if name[i] > name[i+1] :
temp = name[i]
name[i] = name[i+1]
name[i+1] = temp
return name
def printdata (name) :
for i in range (0, 4) :
print ('The data in cell [%d] is %s ' % ((i+1), name[i]))
name = [0] * 4
for i in range (0, 4) :
name[i] = raw_input('Enter string[%d] ' % (i+1))
name = bubble (name)
print ('\nThe sorted data is ')
printdata (name)