#Usage of Arithmetic operators
#Variable declaration
i=10
j=20
#the sum value of variables i and j stores in k variable
k=i+j
#Result
print "Value of k is %d"%(k)
# Demonstrations on arithmetic operators
#User Input
a,b,c,d=input("Enter values of a, b, c, d: ")
#Calculation
a+=(b*c)+d
#Result
print "Value of a = %d "%(a)
#Find out all arithmetic operation on two given values
#Variable Declaration
sum=sub=mul=rem=0
div=0.0
a=0
#User Input
b,c,d=input("Enter the values of b, c, d: ")
sum = b + c
sub = b - c
mul = b * c
div = b/c
rem = b % d
print "Sum = %d, Sub = %d, Mul = %d, Div = %f"%(sum,sub,mul,div)
print "Remainder of division of b & d is %d"%(rem)
print "a=%d"%(a)
#Program to use various relational operators
#!=,==,>=,<= are assignment operator
print "Condition : Return values"
print " 5!=5 : %5d"%(5!=5)
print " 5==5 : %5d"%(5==5)
print " 5>=5 : %5d"%(5>=5)
print " 5<=5 : %5d"%(5<=50)
print " 5!=3 : %5d"%(5!=3)
# Demonstrate of logical operator
#Variable Declaration
c1=c2=c3=0
#USer Input
c1,c2,c3=input("Enter Values of C1, C2 and C3: ")
print "\n"
if (c1<c2) and (c1<c3):
print "C1 is less than C2 and C3"
if not(c1) < (c2 ):
print "C1 is greater than C2"
if ((c1 < c2 or c1 < c3)):
print "C1 is less than C2 or C3 or both"
#else:
# print "Something went wrong. Check"
#Demonstration of assignment operator
#Variable Declaration
i=4
j=5
#'=' is assignment operator
i=j
k=i
#Result
print "K = %d"%(k)
#Program using Increment and Decrement Operator.
#Variable Declaration
a=10
#There is no post and pre increment in python
#There is no post and pre decrement in python
#Result
print "The Value of a = %d"%(a)
print "Increment of a = %d"%(a+1)
print "Decrement of a = %d"%(a-1)
#Program using increment and decrement operators
#Variable Declaration
i=3
j=4
#No Pre Decrement and Pre Increment in python
i=i+1 #Increment value
j=j-1 #Decrement value
k=i+j
#Result
print "i = %d, j = %d, k = %d"%(i,j,k)
#Program to illustrate sizeof operator
import sys
num=int(1234567890)
dec=float(0.123456)
ext=0.123456789
ltr='A'
string="Something to write home about...."
class struct():
a=0
boy=struct()
#Result
print "Size of num is in %d bytes."%(sys.getsizeof(num))
print "Size of dec is in %d bytes."%(sys.getsizeof(dec))
print "Size of ext double is in %d bytes."%(sys.getsizeof(ext))
print "Size of ltr char is in %d bytes."%(sys.getsizeof(ltr))
print "Size of the string is in %d bytes."%(sys.getsizeof(string))
print "Size of struct is in %d bytes."%(sys.getsizeof(struct()))
#Convert number of days to months and days
#Variable Declaration
m=0
d=0
#User Input
nd=input("Enter the number of days= ")
m=nd/30
d=nd%30
#Result
print "Number of months...", m
print "Number of days...", d
#Calculate Salesman Salary
#Variable Declaration
BASIC=2500
BONUS_RATE=200
COM=0.02
qty=0
GS=price=Bonus=Comm=0.0
#User input
qty,price=input("Enter the number of items Sold and Price...: ")
Bonus=BONUS_RATE*qty
Comm=COM*qty*price
GS=BASIC+Bonus+Comm
print "Bonus.... %6.2f"%(Bonus)
print "Commission.... %6.2f"%(Comm)
print "Gross Salary... %6.2f"%(GS)
#Post increment using different storage classes
#Defining function
def postinc():
x=1
print "X = %d" %(x)
x=x+1
#Call Function
postinc()
postinc()
postinc()