1: Numbers

Example number 1.1, Page number 1.12

In [1]:
#importing modules
import math
from __future__ import division

#Variable declaration
D=41;     #divisor
d=15625;   #dividend

#Calculation
q=d/D;    #quotient
r=d%D;    #remainder

#Result
print "quotient is",q
print "remainder is",r
quotient is 381.097560976
remainder is 4

Example number 1.2, Page number 1.12

In [2]:
#importing modules
import math
from __future__ import division

#Variable declaration
D=397246;    #dividend
r=211;   #remainder
q=865;   #quotient

#Calculation
d=(D-r)/q;    #divisor

#Result
print "divisor is",d
divisor is 459.0

Example number 1.4, Page number 1.13

In [3]:
#importing modules
import math
from __future__ import division

#Variable declaration
d=87375;    #dividend
D=698;    #divisor

#Calculation
r=d%D;    #remainder

#Result
print "least number to be subtracted is",r
least number to be subtracted is 125

Example number 1.5, Page number 1.13

In [4]:
#importing modules
import math
from __future__ import division

#Variable declaration
d=49123;    #dividend
D=263;    #divisor

#Calculation
r=d%D;    #remainder
l=D-r;   #least number to be added

#Result
print "least number to be added is",l
least number to be added is 58

Example number 1.6, Page number 1.13

In [5]:
#importing modules
import math
from __future__ import division

#Variable declaration 
d=999;   #dividend
D=35;    #divisor

#Calculation
r=d%D;    #remainder
rn=d-r;    #required number

#Result
print "required number is",rn
required number is 980

Example number 1.7, Page number 1.13

In [6]:
#importing modules
import math
from __future__ import division

#Variable declaration 
d=100;   #dividend
D=14;    #divisor

#Calculation
r=d%D;    #remainder
rn=d+D-r;    #required number

#Result
print "required number is",rn
required number is 112

Example number 1.8, Page number 1.13

In [7]:
#importing modules
import math
from __future__ import division

#Variable declaration 
d=602;   #dividend
D=14;    #divisor
rl=36;   #remainder

#Calculation
k=d/D;    #quotient
rs=rl-(2*D);    #required remainder

#Result
print "required remainder is",rs
required remainder is 8

Example number 1.9, Page number 1.13

In [8]:
#importing modules
import math
from __future__ import division

#Variable declaration 
d=357;   #dividend
D=17;    #divisor
rs=5;   #remainder

#Calculation
k=d/D;    #quotient
rl=(2*D)+rs;    #required remainder

#Result
print "required remainder is",rl
required remainder is 39

Example number 1.11, Page number 1.25

In [9]:
#importing modules
import math
from __future__ import division

#Variable declaration 
a=30;
b=27;
c=41;     #numbers in decimal form

#Calculation
ba=bin(a);   #binary equivalent of 30
bb=bin(b);   #binary equivalent of 27
bc=bin(c);   #binary equivalent of 41

#Result
print "binary equivalent of 30 is",ba
print "binary equivalent of 27 is",bb
print "binary equivalent of 41 is",bc
binary equivalent of 30 is 0b11110
binary equivalent of 27 is 0b11011
binary equivalent of 41 is 0b101001

Example number 1.12, Page number 1.26

In [44]:
#importing modules
import math
from __future__ import division

#Variable declaration 
a='10110'
b='1011'
c='1001'
d='1010'
e='101'
f='100'
g='1100'
h='11'
i='101'
j='1100'
k='10'

#Calculation
a_b=bin(int(a,2)-int(b,2));     #result of 10110-1011
c_d=bin(int(c,2)+int(d,2));     #result of 1001+1010
e_f=bin(int(e,2)*int(f,2));     #result of 101*100
gh1=int(g,2);
gh2=int(h,2);
gh=int(gh1/gh2);    
g_h=bin(gh);    #result of 1100/11
j_k=bin(int(int(j,2)/int(k,2)));     #result of 1100/10
i_j_k=bin(int(i,2)+int(j_k,2));   #result of 101+1100/10

#Result
print "result of 10110-1011 is",a_b
print "result of 1001+1010 is",c_d
print "result of 101*100 is",e_f
print "result of 1100/11 is",g_h
print "result of 101+1100/10 is",i_j_k
result of 10110-1011 is 0b1011
result of 1001+1010 is 0b10011
result of 101*100 is 0b10100
result of 1100/11 is 0b100
result of 101+1100/10 is 0b1011