a=int
b=int
c=100
distance=float
a=c
b=c+100
distance=55.9
print "a =", a
print "b =", b
print "c =", c
print "distance =", distance
code=int(raw_input("Enter an ASCII code(0-127): "))
symbol=code
print "The symbol corresponding to %d is %c" %(code, symbol)
c=float(raw_input("Enter temperature in Celsius: "))
f=1.8*c+32
print "Equivalent fahrenheit = ", f
f=float(raw_input("Enter temperature in fahrenheit: "))
c=(f-32)/1.8
print "Equivalent Celsius = ", c
from ctypes import c_char, c_short, c_int, c_long, c_float, c_double, c_longdouble, sizeof
print "sizeof( char ) =", sizeof(c_char)
print "sizeof( short ) =", sizeof(c_short)
print "sizeof( short int ) =", sizeof(c_short)
print "sizeof( int ) =", sizeof(c_int)
print "sizeof( long ) =", sizeof(c_long)
print "sizeof( long int ) =", sizeof(c_long)
print "sizeof( float ) =", sizeof(c_float)
print "sizeof( double ) =", sizeof(c_double)
print "sizeof( long double ) =", sizeof(c_longdouble)
numerator=int(raw_input("Enter numerator: "))
denominator=int(raw_input("Enter denominator: "))
result=numerator/denominator
remainder=numerator%denominator
print numerator, "/", denominator, "=", result
print numerator, "%", denominator, "=", remainder
a, b=[int(x) for x in raw_input("Enter two integers <a, b>: ").split()] #taking input in single line sperated by white space
a=a+b
b=a-b
a=a-b
print "Value of a and b on swapping in main():", a, b
my_age=int(raw_input("Enter my age: "))
your_age=int(raw_input("Enter your age: "))
if(my_age==your_age):
print "We are born in the same year."
else:
print "We are born in different years"
from ctypes import c_byte
c=c_byte(255) #signed char
d=c_byte(-1) #signed char
if c.value<0:
print 'c is less than 0'
else:
print 'c is not less than 0'
if d.value<0:
print 'd is less than 0'
else:
print 'd is not less than 0'
if c.value==d.value:
print 'c and d are equal'
else:
print 'c and d are not equal'
from ctypes import c_ubyte, c_byte
c=c_ubyte(255) #unsigned char
d=c_byte(-1) #signed char
if c.value<0:
print 'c is less than 0'
else:
print 'c is not less than 0'
if d.value<0:
print 'd is less than 0'
else:
print 'd is not less than 0'
if c.value==d.value:
print 'c and d are equal'
else:
print 'c and d are not equal'
year=int(raw_input("Enter any year: "))
if( (year%4==0 and year%100!=0) or (year%400==0)):
print year, "is a leap year"
else:
print year, "is not a leap year"
from ctypes import c_uint
u=c_uint(0) #unsigned integer
print 'Value before conversion:', u.value
u.value=~int(u.value) # 1's complement
print 'Value after conversion:', u.value
a=int(raw_input("Enter an integer: "))
n=int(raw_input("Enter bit position to extract: "))
bit=(a>>(n-1))&1 #shift operator
print "The bit is ", bit
a, b=[int(x) for x in raw_input("Enter two integers: ").split()]
larger=a if a>b else b #?: operator
print "The larger of the two is", larger
num=int(raw_input("Enter the number: "))
print "The number", num,"is",
print "Even" if num%2==0 else "Odd" #?: operator
num=int(raw_input("Enter the number: "))
print "The number", num,"is",
print "Even" if num%2==0 else "Odd"
f=float
i=12
j=5
print "when i = ", i, "j = ", j
f=i/j
print "i/j = ", f
f=float(i)/float(j)
print "(float)i/j = ", f
f=float(i)/j
print "float(i)/j = ", f
f=i/float(j)
print "i/float(j) = ", f
CITY='Bidar'
def which_city():
print 'City in Function:',
print CITY
print 'Earlier City:',
print CITY
CITY='Bangalore'
print 'New City:',
print CITY
which_city()
def PrintColor(c):
(red, blue, green)=(0, 1, 2) #enum
type =['red', 'green', 'blue']
if c==red:
color='red'
elif c==blue:
color='blue'
else:
color ='green'
print 'Your color choice as per color2.cpp module:', color
(red, green, blue)=(0, 1, 2) #enum
type =['red', 'green', 'blue']
print 'Your color choice in color1.cpp module: green'
PrintColor(green)
def Max(a, b):
return a if a>b else b
print 'max(2, 3) =', Max(2, 3)
print 'max(10.2, 4.5) =', Max(10.2, 4.5)
i=5
j=10
print 'i =',i
print 'j =', j
print 'On execution of k=max(++i, ++j);...'
i+=1
j+=1
k=Max(i+1, j+1)
print 'i =', i
print 'j =', j #the operand is j+1 and not ++j and thus the change is not reflected back in j.
print 'k =', k #operand of type j+=1 is not allowed
a=30
b=20
c=11
result=a+b/(c-1)+a%b #--c is replaced by (c-1)
print 'a+b/--c+a%b =', result
num1=int(raw_input("Enter the first number: "))
num2=int(raw_input("Enter the second number: "))
print num1, '+', num2, '=',num1+num2
print num1, '-', num2, '=',num1-num2
print num1, '*', num2, '=',num1*num2
print num1, '/', num2, '=',num1/num2