flag=False
print "flag = %r" % flag
flag = True
print "flag = %r" % flag
c='A'
print "c = " + c + ", int(c) = %d" % ord(c)
c='t'
print "c = " + c + ", int(c) = %d" % ord(c)
c='\t' # the tab character
print "c = " + c + ", int(c) = %d" % ord(c)
c='!'
print "c = " + c + ", int(c) = %d" % ord(c)
import sys
# defines the constants SHRT_MIN, etc.
print 'maximum limit int : ',
print sys.maxint
print 'float info'
print sys.float_info
m=54
n=20
print "m = %d and n = %d" %(m,n)
print "m+n = %d" % (m+n) # 54+20 = 74
print "m-n = %d" % (m-n) # 54-20 = 34
print "m*n = %d" % (m*n)# 54*20 = 1080
print "m/n = %d" % (m/n) # 54/20 = 2
print "m modulo by n = %d" % (m%n) # 54%20 = 14
m = 44
m += 1
n = m
print "m = %d , n = %d" %(m,n)
m = 44
n = m # the post-increment operator is applied to m
m += 1
print "m = %d , n = %d" %(m,n)
n=22
print "n = %d" % n
n += 9 # adds 9 to n
print "After n += 9, n = %d" % n
n -= 5 # subtracts 5 from n
print "After n -= 5, n = %d" % n
n *= 2 # multiplies n by 3
print "After n *= 2, n = %d" % n
n /= 3 # divides n by 9
print "After n /= 3, n = %d" % n
n %= 7 # reduces n to the remainder from dividing by 4
print 'After n modulo by 7 n = %d' %n
x=54.0
y=20.0
print "x = %f and y = %f" %(x,y)
print "x+y = %f" %(x+y) # 54.0+20.0 = 74.0
print "x-y = %f" % (x-y) # 54.0-20.0 = 34.0
print "x*y = %f" %( x*y) # 54.0*20.0 = 1080.0
print "x/y = %f" % (x/y) # 54.0/20.0 = 2.7
import sys
print "Number of bytes used:\n"
print " char: %d " % sys.getsizeof('a')
print " int : %d " % sys.getsizeof(int(1))
print " string : %d " % sys.getsizeof(str('hellololdei'))
print "float : %d" % sys.getsizeof(float(1.1))
import sys
fbits = 8*sys.getsizeof(float(123))
# each byte contains 8 bits
print "float uses : %d bits:\n\t" % fbits
v = 1234.56789
n = int(v);
print "v = %f, n = %d" %(v,n)
c='A'
print "char c = " + c
k=c;
print "k = " + k
m=k;
print "m = " + m
n=m
print "n = " + n
x=m
print "x = " + x
y=x
print "y = " + y
n=1000
print "n = %d" % n
n *= 1000 # multiplies n by 1000
print "n = %d" % n
n *= 1000 # multiplies n by 1000
print "n = %d" % n
n *= 1000 # multiplies n by 1000
print "n = %d" % n
x=1000.0
print "x = %f" % x
x *= x # multiplies n by itself; i.e., it squares x
print "x = %f" % x
x *= x # multiplies n by itself; i.e., it squares x
print "x = %f" % x
x *= x # multiplies n by itself; i.e., it squares x
print "x = %f" % x
x *= x # multiplies n by itself; i.e., it squares x
print "x = %f" % x
x = 1000/3.0
print "x = %f" %x # x = 1000/3
y = x - 333.0
print "y = %f" % y # y = 1/3
z = 3*y - 1.0
print "z = %f" %z # z = 3(1/3) - 1
if (z == 0):
print "z == 0.\n"
else:
print "z does not equal 0.\n" # z != 0
import math
a = float(raw_input("Enter the coefficients of a quadratic equation:\n a : "))
b = float(raw_input('b : '))
c = float(raw_input('c : '))
print "The equation is: ",
print a,
print "*x*x + ",
print b,
print "*x + " ,
print c,
print " = 0"
d = b*b - 4*a*c # discriminant
sqrtd = math.sqrt(d)
x1 = (-b + sqrtd)/(2*a)
x2 = (-b - sqrtd)/(2*a)
print "The solutions are:"
print "\tx1 = %f" % x1
print "\tx2 = %f" % x2
print "Check:"
print "\ta*x1*x1 + b*x1 + c = %f" %( a*x1*x1 + b*x1 + c)
print "\ta*x2*x2 + b*x2 + c = %f" %( a*x2*x2 + b*x2 + c)
x = float(raw_input("Enter float: "))
print "Its reciprocal is: ",
print 1/x
x = 11
# ERROR: this is not in the scope of x
if True:
x = 22 # OK: this is in the scope of x
y = 33 # ERROR: this is not in the scope of y
x = 44 # OK: this is in the scope of x
y = 55 # OK: this is in the scope of y
x = 66 # OK: this is in the scope of x
y = 77 # ERROR: this is not in the scope of y
# this x is global
x = 11
if True:
# illustrates the nested and parallel scopes:
x = 22
# begin scope of internal block
if True:
x = 33
print "In block inside main(): x = %d " % x
# end scope of internal block
print "In main(): x = %d" %x
print "In main(): x = %d "% x