Question

Use python def a function that takes in a list of passwords (as strings), a password...

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

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python function first_chars that takes one parameter, which is a nested list of strings....
Write a Python function first_chars that takes one parameter, which is a nested list of strings. It returns a string containing the first character of all of the non-empty strings (at whatever depth they occur in the nested list) concatenated together. Here are a couple of examples of how the function should behave when you're done: >>> first_chars(['Boo', 'is', 'happy', 'today']) 'Biht' >>>first_chars(['boo', 'was', ['sleeping', 'deeply'], 'that', 'night', ['as', ['usual']]]) 'bwsdtnau'
[Python] Write a function named "total_population" that takes a string then a list as parameters where...
[Python] Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a list containing 3 strings as elements representing the CountryCode, CityName, and Region in this order. Return the total population of all cities in the list. Note that the city must match the country, name, and...
8) Write Python code for a function called occurances that takes two arguments str1 and str2,...
8) Write Python code for a function called occurances that takes two arguments str1 and str2, assumed to be strings, and returns a dictionary where the keys are the characters in str2. For each character key, the value associated with that key must be either the string ‘‘none’’, ‘‘once’’, or ‘‘more than once’’, depending on how many times that character occurs in str1. In other words, the function roughly keeps track of how many times each character in str1 occurs...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function `g` representing an increasing function g(x) 2) a number `gmin`, and returns an integer `nmin` such that nmin>0 is the smallest integer that satisfies g(nmin)>gmin. test: def g(n): return 2*n print(lowest_integer(g, 10)) Output: 6
Python Mutable Sequences Implement a function reverse that takes a list as an argument and reverses...
Python Mutable Sequences Implement a function reverse that takes a list as an argument and reverses the list. You should mutate the original list, without creating any new lists. Do NOT return anything. Do not use any built-in list functions such as reverse(). def reverse(lst):    """Reverses lst in place (i.e. doesn't create new lists).     >>> L = [1, 2, 3, 4]     >>> reverse(L)     >>> L     [4, 3, 2, 1]     """
Python: Complete the function create_bfs_graph using python. Do not use any libraries def create_bfs_graph(): """ Initializes...
Python: Complete the function create_bfs_graph using python. Do not use any libraries def create_bfs_graph(): """ Initializes the undirected graph from the lecture    Uses the add_edge method    Returns Graph object of the lecture graph Example use: >>> ex_graph = create_bfs_graph() >>> [x in ex_graph.children_of('Jared') for x in ['John', 'Helena', 'Donald', 'Paul']] [False, False, True, True] >>> ex_graph = create_bfs_graph() >>> [x in ex_graph.children_of('Helena') for x in ['John', 'Helena', 'Donald', 'Paul']] [True, False, False, True] """ # DON'T CHANGE ANYTHING...
1.Implement a function which will -       + Accept a number, num, and a list, my_list...
1.Implement a function which will -       + Accept a number, num, and a list, my_list as arguments       + return True if num exists in my_list       + return False otherwise 2. Write Python code to implement the following function - def find_in_list(item, my_list):     """     Look for an item from my_list (of items.)     If the item is found, return the index position of the item;     otherwise, return -1.     """       #add your code here...
For each of the following Python programs P and input strings I, give the output P(I),...
For each of the following Python programs P and input strings I, give the output P(I), using the formal definition of P(I) given, and employing any reasonable reference computer C: Definition of P(I), the output of a Python program. Let P be a Python program with respect to a reference computer system C. Suppose P has main function M, and let I be a string of ASCII characters that will be used as input to P. The output of P...
Python #Write a function called are_anagrams. The function should #have two parameters, a pair of strings....
Python #Write a function called are_anagrams. The function should #have two parameters, a pair of strings. The function should #return True if the strings are anagrams of one another, #False if they are not. # #Two strings are considered anagrams if they have only the #same letters, as well as the same count of each letter. For #this problem, you should ignore spaces and capitalization. # #So, for us: "Elvis" and "Lives" would be considered #anagrams. So would "Eleven plus...
Write a Python function count_bigger that takes two parameters, a nested list of objects and a...
Write a Python function count_bigger that takes two parameters, a nested list of objects and a threshold number. It returns an integer specifying how many of the objects anywhere in the nested list are numbers that are larger than the threshold. (For our purposes, "numbers" are either integers or floats.) There may be objects in the list other than numbers, in which case you would simply ignore them. Here are a couple of examples of how the function should behave...