From 1789aa1b81fbfc1a1bb1a6fe1fe6b754b82acc98 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Sun, 2 Feb 2020 11:23:16 -0500 Subject: [PATCH] Stopwatch can now be concat to a string without any extra function calls --- Stopwatch.py | 9 +++++++++ testStopwatch.py | 1 + 2 files changed, 10 insertions(+) diff --git a/Stopwatch.py b/Stopwatch.py index 3c9626c..a9b7b49 100644 --- a/Stopwatch.py +++ b/Stopwatch.py @@ -155,3 +155,12 @@ class Stopwatch: #Return the string return timeString + + def __str__(self): + return self.getString() + + def __add__(self, other): + return self.getString() + other + + def __radd__(self, other): + return other + self.getString() diff --git a/testStopwatch.py b/testStopwatch.py index 7508347..7197ec3 100644 --- a/testStopwatch.py +++ b/testStopwatch.py @@ -73,6 +73,7 @@ else: #Print the results print("\nHere is a printing of the different times, starting with the string:") +print("It took " + timer + " to run this algorithm") print("It took " + timer.getString() + " to run this algorithm") print("It took " + str(timer.getNanoseconds()) + " nanoseconds to run this algorithm") print("It took " + str(timer.getMicroseconds()) + " microseconds to run this algorithm")