Open main menu

CDOT Wiki β

Changes

OPS445 Online Lab7

9 bytes added, 16:35, 14 November 2023
added double 02d to f-string: fix for new version of python
def format_time(t):
"""Return time object (t) as a formatted string"""
return f'{t.hour:0202d}:{t.minute:0202d}:{t.second:0202d}'
def sum_times(t1, t2):
def format_time(self):
"""Return time object (t) as a formatted string"""
return f'{self.hour:0202d}:{self.minute:0202d}:{self.second:0202d}'
def sum_times(self, t2):
def __str__(self):
'''return a string representation for the object self'''
return f'{self.hour:0202d}:{self.minute:0202d}:{self.second:0202d}'
</source>
:1. Make a copy of lab7d.py and name it as lab7e.py. Add the function definition for __str__() after the __init__() function in lab7e.py. Make sure that the '''def __str__(self):''' line has the same indentation level as the __init__() function.