In: Computer Science
Need to modify the below code to return the time in minutes instead of seconds.
(Using Python 2.7.6 )
def numberPossiblePasswords(numDigits,
numPossiblePerDigit):
numPasswords =
numPossiblePerDigit**numDigits
return numPasswords
def maxSecondsToCrack(numPossiblePasswords, secPerAttempt):
time = numPossiblePasswords*secPerAttempt
return time
nd = int(input("How many digits long is the passcode?
"))
nc = int(input("How many possible characters are there per digit?
"))
secondsPerAttempt = .08
npp = numberPossiblePasswords(nd, nc)
totalSeconds = maxSecondsToCrack(npp, secondsPerAttempt)
print("It will take you " + str(totalSeconds) + " seconds maximum
to crack the password.")
# Below highlighted lines are modified. Since a minute has 60 seconds, divided the returning value by 60.
import math
def numberPossiblePasswords(numDigits,
numPossiblePerDigit):
numPasswords =
numPossiblePerDigit**numDigits
return numPasswords
def maxSecondsToCrack(numPossiblePasswords,
secPerAttempt):
time = numPossiblePasswords*secPerAttempt
return math.ceil(time/60)
nd = int(input("How many digits long is the passcode?
"))
nc = int(input("How many possible characters are there per digit?
"))
secondsPerAttempt = .08
npp = numberPossiblePasswords(nd, nc)
totalSeconds = maxSecondsToCrack(npp, secondsPerAttempt)
print("It will take you " + str(totalSeconds) + " minutes maximum
to crack the password.")
# Hit the thumbs up if you are fine with the answer. Happy Learning!