Open main menu

CDOT Wiki β

Changes

OPS445 Online Lab7

7 bytes removed, 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.2dhour:%.2d02d}:%.2d' % (t.hour, {t.minute, :02d}:{t.second):02d}'
def sum_times(t1, t2):
def format_time(self):
"""Return time object (t) as a formatted string"""
return f'%{self.2dhour:%.2d02d}:%.2d' % (self.hour, {self.minute, :02d}:{self.second):02d}'
def sum_times(self, t2):
def __str__(self):
'''return a string representation for the object self'''
return f'%{self.2dhour:%.2d02d}:%.2d' % (self.hour, {self.minute, :02d}:{self.second) :02d}'
</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.