Updated all problems to use fstrings and results()

This commit is contained in:
2020-10-30 16:20:39 -04:00
parent ad458278d4
commit 46216a2807
33 changed files with 280 additions and 452 deletions

View File

@@ -1,7 +1,7 @@
#ProjectEulter/Python/Project5.py
#Matthew Ellison
# Created: 01-28-19
#Modified: 10-29-20
#Modified: 10-30-20
#What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
"""
@@ -73,17 +73,19 @@ class Problem5(Problem):
#Throw a flag to show the problem is solved
self.solved = True
#Reset the problem so it can be run again
def reset(self):
super().reset()
self.smallestNum = 0
#Gets
#Returns the result of solving the problem
def getResult(self):
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before you can see the result")
return "The smallest positive number that is evenly divisible by all numbers 1-20 is " + str(self.smallestNum)
#Gets
return f"The smallest positive number that is evenly divisible by all numbers 1-20 is {self.smallestNum}"
#Returns the requested number
def getNumber(self) -> int:
#If the problem hasn't been solved throw an exceptions
@@ -92,15 +94,6 @@ class Problem5(Problem):
return self.smallestNum
#If it are running this file, automatically start the correct function
if __name__ == '__main__':
problem = Problem5()
print(problem.getDescription()) #Print the description of the problem
problem.solve() #Solve the problem
#Print the results
print(problem.getResult())
print("It took " + problem.getTime() + " to solve this algorithm")
"""Results:
The smallest positive number that is evenly divisible by all numbers 1-20 is 232792560
It took an average of 54.833 seconds to run this problem through 100 iterations