import sys
# Calculation and result
i = 0
for arg in sys.argv :
print ('arg [%d] - %s' % (i, arg))
i = i+1
%run 10.1.py hello world
import sys
# Function declaration, calculation and result
if len(sys.argv) != 2 :
print ('Inappropriate number of arguments')
total = 0
def fact (n) :
total = n
while n > 1 :
total = total * (n - 1)
n = n - 1
return total
print ('Factorial of %d is %d ' % (int(sys.argv[1]), fact (int(sys.argv[1]))))
%run 10.2.py 5
import sys
# Function declaration
def printdata () :
i = 0
for arg in sys.argv[1:] :
print ('The data in cell [%d] is %s ' % (i, arg))
i = i+1
# Calculation and result
print ('The names before sorting are ')
printdata ()
sys.argv.sort()
print ('The names after sorting are ')
printdata ()
%run 10.3.py zimbabwe nigeria argentina china hongkong
# Variable declaration
a = int(raw_input('Enter any positive number '))
# Function declaration, calculation and result
def convert (a) :
return int(bin(a)[2:])
bits = str(convert (a))
print ('Number of bits = %d' % (len(bits)))
print ('Binary equivalent is : %d' % (convert (a)))
# Variable declaration
a = int(raw_input('Enter first number : '))
b = int(raw_input('Enter second number : '))
# Calculation and result
b = ~b + 1
c = a + b
print ('Subtraction is = %d ' % c)
# Variable declaration
a = int(raw_input('Enter first number : '))
original_a = a
b = int(raw_input('Enter second number : '))
original_b = b
# Calculation and result
c = 1
while (b) :
if (b & 1) :
c = c * a
b = b >> 1
a = a * a
print ('%d raise to %d = %d ' % (original_a, original_b, c))