Use python def a function that takes in a list of passwords (as
strings), a password that
needs to be checked (as a string), and an integer that represents
the
number of repetitions. If the given password occurs given number of
times,
return True, else return False.
eg. >>> repeats(["ma48", "ma28", "ma48"], "ma48",
2)
True
>>> repeats(["ma48", "ma28", "ma48"], "ma48", 3)
False
>>> repeats(["ma48", "ma28", "ma48", "ma28", "ma48"],
"ma38", 2)
False
>>> repeats(["ma48", "ma28", "ma48", "ma38"], "ma48",
1)
False
Program:
passwordsList = ["ma48", "ma28", "ma48"]
password = "ma48"
count = 2
def checkRepeats(list, pwd, repeats):
count = 0
for word in list: # Loops runs through the list
if word == pwd: # Compare every word with passed password
count = count + 1 # if word is same increase the count
if count == repeats: # if word count and repeats are equal
print(True) # print true
else:
print(False) # else print false
checkRepeats(passwordsList, password, count)
Output:
Get Answers For Free
Most questions answered within 1 hours.