#Variable declaration
s = 0
marks = [] # array declaration
#for i in range(0,30):
# marks.append(int(raw_input("Enter marks: " ))) # store data in array
marks = [89,85,57,25,90,45,87,48,98,12,39,66,75,30,87,100,5,78,56,99,84,0,39,79,93,61,87,45,90,56]
print "Enter marks: "
for i in range(0,30):
print marks[i]
for i in range(0,30):
s = s + marks[i] # read data from array
#Calculation
avg = s / 30 #Average formula
#Result
print "Average marks = ", avg
#Funcion definition
def display(m):
print m
#Variable declaration
marks = [ 55, 65, 75, 56, 78, 78, 90 ] #array
for i in range(0,7):
display(marks[i]) #function call
#Funcion definition
def display(n):
print n #return
#Variable declaration
marks = [ 55, 65, 75, 56, 78, 78, 90 ] #array
for i in range(0,7):
display(marks[i]) #function call
#Variable declaration
i = 3
j = 1.5
k = 'c'
print "Value of i = ", i
print "Value of j = ", j
print "Value of k = ", k
#addresses of the variables
x = id(i)
y = id(j)
z = id(k)
print "Original address in x = ", x
print "Original address in y = ", y
print "Original address in z = ", z
x += 2
y += 4
z += 1
print "New address in x = ", x
print "New address in y = ", y
print "New address in z = ", z
#Variable declaration
arr = [ 10, 20, 30, 45, 67, 56, 74 ]
i = id(arr[1]) #address
j = id(arr[5]) #Address
#Result
print j - i, arr[5] - arr[1]
#Variable declaration
arr = [ 10, 20, 36, 72, 45, 36 ]
j = id(arr[ 4 ])
k = id( arr[0 + 4] )
#Result
if j == k : #comparison
print "The two pointers point to the same location"
else:
print "The two pointers do not point to the same location"
#Variable declaration
num = [ 24, 34, 12, 44, 56, 17]
#Result
for i in range(0,6):
print "element no. ", i
print "address = ", id(num[i])
#Variable declaration
num = [ 24, 34, 12, 44, 56, 17]
#Result
for i in range(0,6):
print "address = ", id(num[i])
print "element = ", num[i]
#Variable declaration
num = [ 24, 34, 12, 44, 56, 17]
j = id(num[0]) # assign address of zeroth element
#Result
for i in range(0,6):
print "address = ", j
print "element = ", num[i]
j = id(num[(i+1)%6]) # increment pointer to point to next location
#Variable declaration
num = [ 24, 34, 12, 44, 56, 17 ]
#Function definition:
def display ( j,n ):
for i in range(0,n):
print "element = ", j
j = num[(i+1)%n] #increment pointer to point to next element
display ( num[0], 6 ) #function call
#Variable declaration
num = [ 24, 34, 12, 44, 56, 17]
for i in range(0,6):
print "address = ", id(num[i])
print "element = ", num[i], num[(0+ i)]
print num[(i+0)], num[i]
#Variable declaration
stud = [] #array
#for i in range(0,4):
# stud.append((raw_input("Enter roll no and marks: ").split())) # storing data in the 2D array
stud = ["1 38","2 78","3 93","4 48"]
for i in range (0,4):
print "Enter roll no and marks: "
print stud[i]
#Result
for i in range(0,4):
print stud[i][0],stud[i][1:]
#Variable declaration
s = [ [1234, 56 ], [ 1212, 33], [ 1434, 80 ], [ 1312, 78 ]]
#Result
for i in range(0,4):
print "Address of %d th 1-D array = %u"%( i, id(s[i]) )
#Variable declaration
s = [ [ 1234, 56 ], [ 1212, 33 ], [ 1434, 80 ], [ 1312, 78 ] ]
for i in range(0,4):
for j in range(0,2):
print s[i][j]
#Variable declaration
s = [ [ 1234, 56 ], [ 1212, 33 ], [ 1434, 80 ], [ 1312, 78 ]]
#Result
for i in range(0,4):
p = s[i]
pint = p
print "\n"
for j in range(0,2):
print pint[j]
#Variable declaration
a = [[1, 2, 3, 4] , [5, 6, 7, 8] , [9, 0, 1, 6 ]]
#Function definitions
def display ( q, row, col ):
for i in range(0,row):
for j in range(0,col):
print q [ (i * col)%3][j]
print "\n"
print "\n"
def show ( q, row, col ):
for i in range(0,row):
p = q[i]
for j in range(0,col):
print p[j]
print "\n"
print "\n"
def Print ( q, row, col ):
for i in range(0,row):
for j in range(0,col):
print q[i][j]
print "\n"
print "\n"
#function calls
display ( a, 3, 4 )
show ( a, 3, 4 )
Print ( a, 3, 4 )
from ctypes import *
#Variable declaration
arr = [] # array of integer pointers
i = c_int(31)
j = c_int(5)
k = c_int(19)
l = c_int(71)
arr.append(pointer(i))
arr.append(pointer(j))
arr.append(pointer(k))
arr.append(pointer(l))
for m in range(0,4):
print arr[m].contents
#Variable declaration
a = [ 0, 1, 2, 3, 4 ]
p = [ a[0], a[1], a[2], a[3], a[4] ]
#Result
print p, id(p), id(id(p ) )