Lab Cycle
Lab Cycle
'''Write a python program to define a module to find Fibonacci Numbers and import the
module to another program'''
#import fibonacci module
import fibonacci
num=int(input("Enter any number to print Fibonacci series "))
fibonacci.fib(num)
5 Write a python program to define a module and import a specific function in that module
to another program
'''Write a python program to define a module and import a specific function in that
module to another program.'''
from arth import Add
num1=float(input("Enter first Number : "))
num2=float(input("Enter second Number : "))
print("Addition is : ",Add(num1,num2))
print("Subtraction is : ",Sub(num1,num2)) #gives error:Not importing Sub function from arth
Module
6.
'''Write a Python class to convert an integer to a roman numeral.'''
class irconvert:
num_map = [(1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'), (100, 'C'), (90, 'XC'),(50, 'L'), (40,
'XL'), (10, 'X'), (9, 'IX'), (5, 'V'), (4, 'IV'), (1, 'I')]
def num2roman(self,num):
roman = ''
while num > 0:
for i, r in self.num_map:
while num >= i:
roman += r
num -= i
return roman
8.
'''Write a Python class to implement pow(x, n)'''
class py_pow:
def powr(self, x, n):
if x==0 or x==1 or n==1:
return x
if x==-1:
if n%2 ==0:
return 1
else:
return -1
if n==0:
return 1
if n<0:
return 1/self.powr(x,-n)
val = self.powr(x,n//2)
if n%2 ==0:
return val*val
return val*val*x