from ctypes import c_int,c_uint
SignedInt = c_int(2000000000)
unsignVar = c_uint(2000000000)
SignedResult=c_int(0)
UnsignedInt=c_uint(0)
#calculation result exceeds range of permitted values
SignedResult.value = (SignedInt.value * 2)
SignedResult.value =SignedResult.value / 3
#calculation result is within permissible range
UnsignedResult = (SignedInt.value * 2) / 3;
print "Demonstrates wrong result caused by exceeding range"
print "Signed Integer Calculation giving result as: "
print "(",SignedInt.value,
print "*2)/3= ",SignedResult.value
print "Demonstrates correct result caused by permissible range"
print "Unsigned Integer Calculation giving result as: "
print "(",UnsignedInt.value,
print "*2)/3= ",UnsignedResult
#variable declaraton
a=10
b=5
print 'a= ',a, #printing the values
print ', b= ',b
a=b
print 'a= ',a,
print ', b= ',b
b=7
print 'a= ',a,
print ', b= ',b
#The ++ operator is not available in Python
a=10
b=5
c=15
print 'a= ',a,
print ', b= ',b,
print ', c= ',c
a=a+1 #no preincrement syntax in python
c=a+b
b=b+1
print 'a= ',a,
print ', b= ',b,
print ', c= ',c
a=10
b=5
c=15
print 'a= ',a,
print ', b= ',b,
print ', c= ',c #no preincrement syntax in python
c=a+b
a=a+1
b=b+1
print 'a= ',a,
print ', b= ',b,
print ', c= ',c
from ctypes import c_short,c_long
SignedShort = c_short(30000)
SignedShort.value=SignedShort.value*10
SignedShort.value=SignedShort.value/10
print 'SignedShort= ',SignedShort.value #wrong answer
SignedShort=30000
#result within limits
SignedLong=(c_long)(SignedShort*10)
SignedLong=(c_long)(SignedShort/10)
print 'SignedShort= ',SignedShort #right answer