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
>>>
No comments:
Post a Comment