Question

In: Computer Science

Python Problem 3 Write a function named enterNewPassword. This function takes no parameters. It prompts the...

Python Problem 3

Write a function named enterNewPassword. This function takes no parameters. It prompts the user to enter a password until the entered password has 8-15 characters, including at least one digit. Tell the user whenever a password fails one or both of these tests.

Solutions

Expert Solution

def enterNewPassword():

    while True:

   

        # get user input

        password = input('Enter password : ')

       

        # if the length is not in range 8 - 15

        if len(password) < 8 or len(password) > 15:

       

            print('Error! Password is not in range 8-15')

           

        digit_count = 0

       

        arr = [ '1' , '2', '3', '4', '5', '6', '7', '8', '9', '0' ]

       

        # traverse the string and count the number of digits

        for ch in password:

       

            # if current character is digit

            if ch in arr:

           

                digit_count += 1

               

        # if there is not digit

        if digit_count < 1:

       

            print('Error! There must be atleast 1 digit')

            

        # if password is correct

        if len(password) >= 8 and len(password) <= 15 and digit_count >= 1:

       

            print('Correct password')

            return

           

        print()

       

enterNewPassword()


Sample Output


Related Solutions

Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints...
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints a message with information about the total amount owed and how much the tip was. As a reminder, the tip amounts are 10%, 15% and 20% for stingy, regular, and generous customers. And the tax amount should be 7%. The total amount is calculated as the sum of two amounts: check_amount = base_cost*1.07 tip_amount = tip_percentage*check_amount To receive full credit, you must use string...
Write a function named "check_matrix" which takes two matrices as parameters and returns 1 if the...
Write a function named "check_matrix" which takes two matrices as parameters and returns 1 if the matrices are same or 0 otherwise. Set appropriate parameters and return type if necessary.
Write a recursive function named multiply that takes two positive integers as parameters and returns the...
Write a recursive function named multiply that takes two positive integers as parameters and returns the product of those two numbers (the result from multiplying them together). Your program should not use multiplication - it should find the result by using only addition. To get your thinking on the right track: 7 * 4 = 7 + (7 * 3) 7 * 3 = 7 + (7 * 2) 7 * 2 = 7 + (7 * 1) 7 *...
Write a Python program: The function is named validity(). It receives 2 floating point parameters, min...
Write a Python program: The function is named validity(). It receives 2 floating point parameters, min and max, from the program that invoked it. The function asks the user to enter a float number. Using a while loop it checks whether the number is valid (between min and max, inclusive). If not valid, the while loop uses this statement to prompt for a new number: num = float (input (" Enter a number that is at least :"+ str(min) +...
Define a Python function named matches that has two parameters. Both parameters will be lists of...
Define a Python function named matches that has two parameters. Both parameters will be lists of ints. Both lists will have the same length. Your function should use the accumulator pattern to return a newly created list. For each index, check if the lists' entries at that index are equivalent. If the entries are equivalent, append the literal True to your accumulator. Otherwise, append the literal False to your accumulator. Hint: Since you must use the same index with each...
(In python) 4. Write a function that involves two arguments, named changeTheCase(myFile, case), that takes, as...
(In python) 4. Write a function that involves two arguments, named changeTheCase(myFile, case), that takes, as arguments, the name of a file, myFile, and the case, which will either be “upper” or “lower”. If case is equal to “upper” the function will open the file, convert all characters on each line to upper case, write each line to a new file, named “upperCase.txt”, and return the string “Converted file to upper case.” If case is equal to “lower” the function...
Problem 2: Caesar Cipher Decryption] Write a python method that takes two parameters: A parameter of...
Problem 2: Caesar Cipher Decryption] Write a python method that takes two parameters: A parameter of type str and a parameter of type int. The first parameter is the plaintext message, and the second parameter is the encryption key. The method strictly does the following tasks: a. Reverse the operations performed by the encryption method to obtain the plaintext message. The method’s header is as follows: def casesardecryption(s, key):
Challenge 3 – Make 2D Array Write a function that takes 3 parameters and makes use...
Challenge 3 – Make 2D Array Write a function that takes 3 parameters and makes use of your prior two functions to create a 2D array filled with a default parameter. var twoD = Init2D(<width>, <height>, <fill val>); Challenge 4 – Random Integer in Range Write a function to return a random integer between a minimum value and maximum value. var ival = IntRandomRange(<min>, <max>); Challenge 5 – Random Int 2D Array Use your prior functions to provide a function...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT