a = 8
b = 4
print "Addition result: ",(a+b)
print "Substraction result: ",(a-b)
print "Multiplication result: ",(a*b)
print "Division result: ",(a/b)
print "Modulus result: ",(a%b)
print "Postfix increment: ",a+1
print "Postfix result: ",a
print "Prefix increment: ",b+1
print "Prefix result: ",b
a = 8
b = 4
print "Assigned values: "
print "a = ",a
print "b = ",b
print "Add & assign: "
a = a + b
print "a += b (8 += 4 ) a = ",a
print "Subtract & assign: "
a = a - b
print "a -= b (12 -= 4 ) a = ",a
print "Multiply & assign: "
a = a * b
print "a *= b (8 *= 4 ) a = ",a
print "Divide & assign: "
a = a / b
print "a /= b (32 /= 4 ) a = ",a
print "Modulus & assign: "
a = a % b
print "a %= b (8 %= 4 ) a = ",a
nil= 0
num= 0
max1 = 1
cap= 'A'
low= 'a'
print "Equality comparisons: "
print "(0 == 0) ",(nil == num),"(true)"
print "(A == a) ",(cap == low),"(false)"
print "Inequality comparison: "
print "(0 != 1) ",(nil != max1),"(true)"
print "Greater comparison: "
print "(0 > 1)",(nil > max1),"(false)"
print "Lesser comparison: "
print "(0 < 1) ",(nil < max1),"(true)"
print "Greater or equal comparison: "
print "(0 >= 0) ",(nil >= num),"(true)"
print "Lesser or equal comparison: "
print "(1 <= 0) ",(max1 <= num),"(false)"
a = 1
b = 0
print "AND logic: "
print "(a && a) ",(a & a),"(true)"
print "(a && b) ",(a & b),"(false)"
print "(b && b) ",(b & b),"(false)"
print "OR logic: "
print "(a || a) ",( a | a ),"(true)"
print "(a || b) ",( a | b ),"(true)"
print "(b || b) ",( b | b ),"(false)"
print "NOT logic: "
print "a = ",a,"!a = ",not a
print "b = ",b,"!b = ",not b
a = 1
b = 2
print "Variable a value is: "
if a != 1:
print "not one"
else:
print "one"
if a % 2 != 0:
print "odd"
else:
print "even"
print "Variable b value is: "
if b != 1:
print "not one"
else:
print "one"
if b % 2 != 0:
print "odd"
else:
print "even"
if a > b:
max1 = a
else:
max1 = b
print "Greater value is ",max1
# there are no few datatypes in ipython so i assigned manually to get idea about size
import sys
num = 1
nums = range(50)
number = 0
max1 = 100
pi = 3.14
decimal = 10.10
letter = 'a'
letters = "hii"
isTrue = "true"
print "int size: ",sys.getsizeof(num)
print "50 int size: ",sys.getsizeof(nums)
print "short int size: ",sys.getsizeof(number)
print "unsigned int size: ",sys.getsizeof(max1)
print "double size: ",sys.getsizeof(pi)
print "float size: ",sys.getsizeof(decimal)
print "char size: ",sys.getsizeof(letter)
print "50 char size: ",sys.getsizeof(letters)
print "bool size: ",sys.getsizeof(isTrue)
num = 1 + 4 * 3
print "Default order: ",num
num = (1 + 4) * 3
print "Forced order: ",num
num = 7 - 4 + 2
print "Default direction: ",num
num = 7 - (4 + 2)
print "Forced direction: ",num
num= 7
factor= 2
letter= 'A'
result= 0.0;
print "Integer division: ",(num/factor)
result = float(num) / factor
print "Cast division float: ",result
num = ord(letter)
print "Cast character int: ",num
letter = chr(70)
print "Cast integer char: ",letter