Python Practical 20
Python Practical 20
class Power:
return x ** n
p = Power()
print(p.compute(2, 3))
class ReverseString:
r = ReverseString()
print(r.reverse("Hello World"))
Q.3 Write a Python class to convert an integer to a roman numeral.
class IntegerToRoman:
roman_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'}
roman = ''
roman += roman_map[value]
num -= value
return roman
r = IntegerToRoman()
print(r.convert(960))
Q.4 Write a Python class that has two methods: get_String and print_String, get_String accept a
string from the user and print_String prints the string in upper case.
class StringOperations:
def get_and_print(self):
print(text.upper())
s = StringOperations()
s.get_and_print()
Q.5 Write a Python class named Rectangle constructed from length and width and a method that
will compute the area of a rectangle.
class Rectangle:
r = Rectangle()
print(r.area(5, 3))