def main():
#Variable Declaration
count=10
int_ptr=count
x=int_ptr
#Result
print("count={0} , x={1}".format(count,x))
if __name__=='__main__':
main()
def main():
#Variable Declaration
c='Q'
char_pointer=c
print("{0} {1}".format(c,char_pointer))
c='/'
char_pointer=c
print("{0} {1}".format(c,char_pointer))
char_pointer='('
c=char_pointer
print("{0} {1}".format(c,char_pointer))
if __name__=='__main__':
main()
def main():
#Variable Declaration
i1=5
p1=i1
i2=p1/2+10
p2=p1
#Result
print("i1 = {0}, i2 = {1}, p1 = {2}, p2 = {3}\n".format(i1, i2, p1, p2))
if __name__=='__main__':
main()
def main():
class date:
def __init__(self): #Class constructor
self.month=0
self.day=0
self.year=0
#Creating instances
today=date()
datePtr=today
datePtr.month=9
datePtr.day=25
datePtr.year=2004
#Result
print("Today's date is {0}/{1}/{2}".format(datePtr.month, datePtr.day, datePtr.year))
if __name__=='__main__':
main()
def main():
class intPtrs:
def __init__(self): #Class constructor
self.p1=0
self.p2=0
#Variable Declarations & Instance creation
i1=100
pointers=intPtrs()
pointers.p1=i1
i2=-97
pointers.p2=i2
#Result
print("i1 = {0}, pointers.p1 = {1}\n".format(i1, pointers.p1))
print("i2 = {0}, pointers.p2 = {1}\n".format(i2, pointers.p2))
if __name__=='__main__':
main()
def main():
class entry:
def __init(self): #Class constructor
self.value=0
self.nxt=0
#Variable declarations & instance creation
n1=entry()
n1.value=100
n2=entry()
n2.value=200
n3=entry()
n3.value=300
n1.nxt=n2
n2.nxt=n3
i=n1.nxt.value
#Result
print("{0}".format(i))
print("{0}".format(n2.nxt.value))
if __name__=='__main__':
main()
def main():
class entry:
def __init__(self): #Class constructor
self.value=0
self.nxt=0
#Creating class instances
n1=entry()
n2=entry()
n3=entry()
list_pointer=n1
#Variable Declaration
n1.value=100
n2.value=200
n3.value=300
n1.nxt=n2
n2.nxt=n3
n3.nxt=0
while(list_pointer!=0): #Calculation
print("{0}\n".format(list_pointer.value))
list_pointer = list_pointer.nxt;
if __name__=='__main__':
main()
def test(int_pointer):
int_pointer=100
return int_pointer
def main():
#Variable declaration
i=50
p=i
print("Before the call to test i = {0}".format(p))
p=test(i) #Function call
print("After the call to test i = {0}".format(p))
if __name__=='__main__':
main()
def exchange(pint1,pint2):
temp=pint1
pint1=pint2
pint2=temp
return pint1,pint2
def main():
#Variable Declaration
i1=-5
i2=66
p1=i1
p2=i2
print("i1 ={0}, i2 ={1}\n".format(i1, i2))
i1,i2=exchange(p1,p2) #Fucntion call-1
print("i1 ={0}, i2 ={1}\n".format(i1, i2))
i1,i2=exchange(i1,i2) #Fucntion call-2
print("i1 ={0}, i2 ={1}\n".format(i1, i2))
if __name__=='__main__':
main()
class entry:
def __init__(self): #Class constructor
self.value=0
selfnxt=0
def FindEntry(listPtr,match): #Function to traverse list
#Calculation
while(listPtr!=0):
if(int(listPtr.value)==int(match)):
return listPtr
else:
listPtr=listPtr.nxt
return 0
def main():
#Creating instance
n1=entry()
n2=entry()
n3=entry()
listPtr=entry()
#Variable declaration
n1.value=100
n2.value=200
n3.value=300
n1.nxt=n2
n2.nxt=n3
n3.nxt=0
listStart=n1
print("Enter value to locate: ")
search=200 #search=raw_input()
listPtr = entry.FindEntry (listStart, search) #Function call
#Result
if ( listPtr != 0 ):
print("Found {0}.\n".format(listPtr.value))
else:
print("Not found.\n")
if __name__=='__main__':
main()
def arraySum (array,n):
#Variable Declaration
sum = 0
arrayEnd = n
#Calculation
for i in range(0,arrayEnd):
sum += array[i]
return sum
def main():
#List Declaration
values = [ 3, 7, -9, 3, 6, -1, 7, 9, 1, -5 ]
#Result
print("The sum is {0}\n".format(arraySum (values, 10)))
if __name__=='__main__':
main()
def arraySum (array,n):
#Variable Declaration
sum = 0
#Calculation
for i in array:
sum += i
return sum
def main():
#List Declaration
values = [ 3, 7, -9, 3, 6, -1, 7, 9, 1, -5 ]
#Result
print("The sum is {0}\n".format(arraySum(values,10)))
if __name__=='__main__':
main()
def copyString(to, frm):
global string2
to=frm
string2=to
def main():
global string2
#String declaration
string1="A string to be copied"
string2=""
copyString(string2,string1) #Functon call
print("{0}\n".format(string2))
copyString (string2, "So is this.") #Function call
print("{0}\n".format(string2))
if __name__=='__main__':
main()
def copyString(to, frm):
global string2
to=frm
string2=to
def main():
global string2
#String declaration
string1="A string to be copied"
string2=""
copyString(string2,string1) #Functon call
print("{0}\n".format(string2))
copyString (string2, "So is this.") #Function call
print("{0}\n".format(string2))
if __name__=='__main__':
main()
def stringLength(string):
return len(string) #Calculation
def main():
print("{0} ".format(stringLength ("stringLength test")))
print("{0} ".format(stringLength ("")))
print("{0}".format(stringLength ("complete")))
if __name__=='__main__':
main()