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 @@
#ProjectEuler/Python/Problem20.py
#Matthew Ellison
# Created: 03-14-19
#Modified: 07-19-20
#Modified: 10-30-20
#What is the sum of the digits of 100!
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
"""
@@ -23,7 +23,6 @@
from Problems.Problem import Problem
from Stopwatch import Stopwatch
from Unsolved import Unsolved
@@ -61,9 +60,6 @@ class Problem20(Problem):
#Stop the timer
self.timer.stop()
#Save the results
self.result = "100! = " + numString + "\nThe sum of the digits is: " + str(self.sum)
#Throw a flag to show the problem is solved
self.solved = True
#Reset the problem so it can be run again
@@ -73,6 +69,12 @@ class Problem20(Problem):
self.sum = 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 f"100! = {self.num}\nThe sum of the digits is: {self.sum}"
#Returns the number 100!
def getNumber(self) -> int:
#If the problem hasn't been solved throw an exception
@@ -86,14 +88,6 @@ class Problem20(Problem):
raise Unsolved("You must solve the problem before you can get the sum")
return self.sum
#This starts the correct function if called directly
if __name__ == "__main__":
problem = Problem20()
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:
100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000