satya

Tuesday, December 22, 2020

Program 29

                                                                            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 convertsectomin(self):
                              n=self.sec
                              minutes=n//60
                              seconds=n%60
                              return(str(minutes)+":"+str(seconds))
               def convertsectohrs(self):
                              n=self.sec
                              hours=n//3600
                              minutes=(n//60)%60
                              seconds=n%60
                               return(str(hours)+":"+str(minutes)+":"+str(seconds))
  
sec = int(input ('Enter the number of seconds:'))
c=Time(sec)
print("Time in minutes :seconds formatted is=",c.convertsectomin())
print("Time in houres :minutes:seconds formatted is=",c.convertsectohrs())



OUTPUT:
========== RESTART: C:/Users/satyanarayana/Desktop/p28.py ==========
Enter the number of seconds:560
Time in minutes :seconds formatted is= 9:20
Time in houres :minutes:seconds formatted is= 0:9:20


========= RESTART: C:/Users/satyanarayana/Desktop/p28.py ===========
Time in minutes :seconds formatted is= 76:7
Time in houres :minutes:seconds formatted is= 1:16:7
>>> 


No comments:

Post a Comment

Program 30

                                                                         Program 30 Write a Python class to implement pow(x, n). class Pow1:...