Question

In: Computer Science

USE PYTHON : # Problem Set 04: - Write a function to seek for all even...

USE PYTHON :

# Problem Set 04:
- Write a function to seek for all even numbers and odd numbers in the middle of two number A and B. Print even and odd numbers in 1 and 2020 (including both these two numbers)

# Problem Set 05:
- A website requests an user to input his account password.
- Write a program to examize the validity of the password.
- The valid password must consists of:
- At least 1 letter in [a-z]
- At least 1 number in [0-9]
- At least a letter in [A-Z] (capital)
- At least one special letter in [$#@]
- At least 6 letters in total
- At most 12 letters in total
- The program can accept a list of passwords that are split by commas.
- Print all valid passwords in a line and split by commas
- Examples:
- Input: ABd1234@1,a F1#,2w3E*,2We3345
- Output: ABd1234@1

Solutions

Expert Solution

In case of any queries, please revert back.

==================== CODE BELOW FOR QUESTION 4 WITH COMMENTS ======================

def get_even_odd(A,B):
    #We use lists for this
    odd_nums = []
    even_nums = []
    # Go over A and B, and store even and odd into respective lists
    for i in range(A,B+1):
        if i%2==0:
            even_nums.append(i)
        else :
            odd_nums.append(i)
    print("Even Numbers are :- ",end=" ")
    for i in even_nums:
        print(i,end=" ")
    print()
    print("Odd Numbers are :- ", end=" ")
    for i in odd_nums:
        print(i, end=" ")

get_even_odd(1, 20)

============== CODE BELOW FOR QUESTION 5 ======================

def check_val(string):
    # Make some checks for number,capital Letter,normal Letter,special Character
    numCheck = False
    capitalLetter= False
    smallLetter = False
    specialLetter = False
    # Now, check each letter in password and check validity
    for letter in string:
        if letter.islower() == True:
            capitalLetter=True
        elif letter.isupper() == True:
            smallLetter = True
        elif letter.isdigit() == True:
            numCheck = True
        else:
            specialLetter = True
    # If all these checks are passed, we check length and return True
    if numCheck==True and capitalLetter==True and smallLetter==True and specialLetter==True:
        if len(string)>=6 and len(string)<=12:
            return True
        return False
    return False

def get_corr_pswd(string):
    # Split the list
    list_pswds = string.split(",")
    for pswd in list_pswds:
        # For each password, check validity and print
        if check_val(pswd)==True:
            print(pswd)

get_corr_pswd("ABd1234@1,a F1#,2w3E*,2We3345")

================ SCREENSHOTS BELOW ========================


Related Solutions

Use the following two loop strategies to write a function that sums all even numbers before...
Use the following two loop strategies to write a function that sums all even numbers before an odd number is observed in any given numeric vector, and test your code in R. For example, if the input vector is 2, 4, -2, 3, 4, 5, then the first odd number appears in the fourth position, which is 3. The output should be the sum of the first to the third numbers, which will be 2 + 4 − 2 =...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
In Python write a function that simulates the throwing of any even numbered dice which will...
In Python write a function that simulates the throwing of any even numbered dice which will be passed on as a parameter: customDice(sides). The function will return a random number rolled for that particular type of dice. Write the program that will utilize the customDice function with the following specification: Ask the user to pick which even-sided dice to use. The program will then roll the dice twice. If the total of both rolls is greater than the number of...
Write a Python function which finds the smallest even and odd numbers in a given list....
Write a Python function which finds the smallest even and odd numbers in a given list. (Use for loop and if conditions for this problem)
Write a function that removes all even numbers from an array. The function should take the...
Write a function that removes all even numbers from an array. The function should take the array, length of the array, and a pointer for number of odd numbers found as arguments and return a pointer to the new array. If there are no odd numbers found in the array, your code should print "No odds found." and return NULL. Use the function header: int *removeEvens(int *a, int length, int *oddsFound); Example: Input array a[ ] = {3, 4, 5,...
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.
In python please write the following code the problem. Write a function called play_round that simulates...
In python please write the following code the problem. Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format '<winning player name> wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
17. Write a function in Python which removes a set of common words from a long...
17. Write a function in Python which removes a set of common words from a long piece of text. Be sure to strip out any punctuation. The common words to be removed are: ​​a, an, as, at, by, for, in, is, it, of, that, this, to, was, will, the These are typical words which are considered to have low semantic value. Process each paragraph provided below individually. Your end result for each paragraph should be a string or list containing...
Write a function in Python which removes a set of common words from a long piece...
Write a function in Python which removes a set of common words from a long piece of text. Be sure to strip out any punctuation. The common words to be removed are: a, an, as, at, by, for, in, is, it, of, that, this, to, was, will, the These are typical words that are considered to have low semantic value. Process each paragraph provided below individually. Your end result for each paragraph should be a string or list containing the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT