Program 30
Write a Python class to implement pow(x, n).
class Pow1:
def poe(self,x,n):
k=x**n
print("pow({},{})={}".format(x,n,k))
p=Pow1()
x=int(input("Enter the X value:"))
n=int(input("Enter the Y value:"))
p.poe(x,n)
Program 30
Write a Python class to implement pow(x, n).
class Pow1:
def poe(self,x,n):
k=x**n
print("pow({},{})={}".format(x,n,k))
p=Pow1()
x=int(input("Enter the X value:"))
n=int(input("Enter the Y value:"))
p.poe(x,n)
Program 31
Write a Python class to reverse a string word by word.
class Sa:
def display(self,s):
words = s.split(' ')
reverse_sentence = ' '.join(reversed(words))
print("The reverse words of string:",reverse_sentence)
k=Sa()
s = input("enter the string:")
k.display(s)
OUTPUT:
=== RESTART: C:/Users/crrcse/Desktop/30.py =======
enter the string:welcome to python
The reverse words of string: python to welcome
>>>
Program 28
Write a class called Time whose only field is a time in seconds. It should have a method called convert_to_minutes that returns a string of minutes and seconds formatted as in the following example: if seconds is 230, the method should return '5:50'. It should also have a method called convert_to_hours that returns a string of hours, minutes, and seconds formatted analogously to the previous method.
class Time:
def __init__(self,sec):
self.sec=sec
def seconds_to_Minutes(self):
s=self.sec
minutes = s // 60
seconds=s%60
print('Times in Minutes:seconds format',str(minutes)+":",str(seconds))
def seconds_to_Hours(self):
s=self.sec
hours = s // 3600
minutes=(s//60)%60
seconds=s%60
print('Times in Hours:Minutes:seconds format',str(hours)+":",str(minutes)+":",str(seconds))
sec=int(input('Enter the number of seconds:'))
obj=Time(sec)
obj.seconds_to_Minutes()
obj.seconds_to_Hours()
OUTPUT:
======RESTART: D:/old/r19 lab-python/28.py =============
Enter the number of seconds:150
Times in Minutes:seconds format 2: 30
Times in Hours:Minutes:seconds format 0: 2: 30
>>>
======RESTART: D:/old/r19 lab-python/28.py =============
Enter the number of seconds:4500
Times in Minutes:seconds format 75: 0
Times in Hours:Minutes:seconds format 1: 15: 0
>>>
Program 30 Write a Python class to implement pow(x, n). class Pow1:...