import sys
ch=' '
int_num=0
flt_num=0.0
dbl_num=0.0
print "The size of char is:",sys.getsizeof(chr),".byte"
print "The size of ch is:",sys.getsizeof(ch),".byte"
print "The size of int is:",sys.getsizeof(int),".byte"
print "The size of int_num is:",sys.getsizeof(int_num),".byte"
print "The size of float is:",sys.getsizeof(float),".byte"
print "The size of flt_num is:",sys.getsizeof(flt_num),".byte"
#As python has no double data type, I have used only float data type here.
num=0
print "The AND operator yields:",(num%2==0 and num%3==0)
num=2
print "The AND operator yields:",(num%2==0 and num%3==0)
num=3
print "The AND operator yields:",(num%2==0 and num%3==0)
num=6
print "The AND operator yields:",(num%2==0 and num%3==0)
#It is not possible to use for-loop in Python the way it is given in textbook. Hence, the use of while loop
num=1
print "Enter a single digit that can be divided \nby both 2 and 3:"
for num in range(2,7):
if(num%2!=0 or num%3!=0):
print num
print num
print "You got such a number:",num
num=7
print "!(n<7) yields:",(not(num<7))
print "!(n>7) yields:",(not(num>7))
print "!(n==7) yields:",(not(num==7))
x=4321
y=5678
print "Given x=",x,",i.e.,0X{:04X}".format(x)
print " y=",y,",i.e.,0X{:04X}".format(y)
z=x&y
print "X & y returns:{:6d}".format(z),",i.e.,0X{:04X}".format(z)
z=x|y
print "X | y returns:{:6d}".format(z),",i.e.,0X{:04X}".format(z)
z=x^y
print "X ^ y returns:{:6d}".format(z),",i.e.,0X{:04X}".format(z)
print " ~X returns:{:6d}".format(~x),",i.e.,0X{:04X}".format(~x)
x=255
y=5
print "Given x={:4d}".format(x),",i.e.,0X{:04X}".format(x)
print " y={:4d}".format(y),",i.e.,0X{:04X}".format(y)
z=x>>y
print "x >> y yields:{:6d}".format(z),",i.e.,0X{:04X}".format(z)
z=x<<y
print "x << y yields:{:6d}".format(z),",i.e.,0X{:04X}".format(z)
import sys
x=sys.getsizeof(int)
if x==2:
print "The int data type has 2 bytes."
else:
print "int doesn’t have 2 bytes."
print "The maximum value of int is: "
if x!=2:
print ~(1 << x * 8 - 1)
else:
print ~(1 << 15)