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/Problem30.py
#Matthew Ellison
# Created: 10-28-19
#Modified: 07-19-20
#Modified: 10-30-20
#Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits.
#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
@@ -65,11 +64,9 @@ class Problem30(Problem):
#Stop the timer
self.timer.stop()
#Save the results
self.result = "The sum of all the numbers that can be written as the sum of the fifth powers of their digits is " + str(sum(self.sumOfFifthNumbers))
#Throw a flag to show the problem is solved
self.solved = True
#Returns a list with the individual digits of the number passed to it
def getDigits(self, num: int) -> list:
listOfDigits = [] #This list holds the individual digits of num
@@ -80,11 +77,19 @@ class Problem30(Problem):
listOfDigits.append(int(digits[cnt]))
#Return the list of digits
return listOfDigits
#Reset the problem so it can be run again
def reset(self):
super().reset()
self.sumOfFifthNumbers.clear()
#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"The sum of all the numbers that can be written as the sum of the fifth powers of their digits is {sum(self.sumOfFifthNumbers)}"
#Returns the top number to be checked
def getTopNum(self) -> int:
#If the problem hasn't been solved throw an exception