Chapter 2 PRIMARY DATA TYPES

Example 2.1, Page No. 32

In [1]:
x=-4443
y=554.21
c='M'

print "The value of integer variable x is" , x
print "The value of float variable y is " , y
print "The value of character variable c is " , c
The value of integer variable x is -4443
The value of float variable y is  554.21
The value of character variable c is  M

Example 2.2, Page No. 36

In [1]:
x = 20
PI = 3.14
print "Constant values are ",x ," and ", round(PI,2)
Constant values are  20  and  3.14

Example 2.3, Page No. 42

In [4]:
print "\t Adder Program, by Michael Vine"
iOperand1=int(raw_input("Enter First Operand: "))
iOperand2=int(raw_input("Enter Second Operand: "))
print "The final result is ", iOperand1+iOperand2
	 Adder Program, by Michael Vine
Enter First Operand: 5
Enter Second Operand: 7
The final result is  12

Example 2.4, Page No. 44

In [5]:
print "\t Adder Program, by Michael Vine"
iOperand1=int(raw_input("Enter First Operand: "))
iOperand2=int(raw_input("Enter Second Operand: "))
iResult=iOperand1+iOperand2
print "The result is ", iResult
	 Adder Program, by Michael Vine
Enter First Operand: 5
Enter Second Operand: 7
The result is  12

Example 2.5, Page No. 46

In [3]:
fRevenue=float(raw_input("Enter total revenue: "))
fCost=float(raw_input("Enter total cost: "))
print "Your total profit is ", round(fRevenue-fCost,3)
Enter total revenue: 4000
Enter total cost: 750
Your total profit is  3250.0