Changes

Jump to: navigation, search

OPS445 Online Lab7

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

Navigation menu