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 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.
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 =...
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...
Python Write a for loop with a range function and format output as currency Use an...
Python Write a for loop with a range function and format output as currency Use an input statement to ask the user for # of iterations using the prompt: #? [space after the ?] & assign to a variable Convert the variable to an integer Use a for loop and a range function to display all whole numbers from 1 to the user entered number Display the value of the item variable on screen in each iteration in the following...
Use Python Write a function that takes a mobile phone number as a string and returns...
Use Python Write a function that takes a mobile phone number as a string and returns a Boolean value to indicate if it is a valid number or not according to the following rules of a provider: * all numbers must be 9 or 10 digits in length; * all numbers must contain at least 4 different digits; * the sum of all the digits must be equal to the last two digits of the number. For example '045502226' is...
Use python write a function that checks the result of the blackjack game, given the sum...
Use python write a function that checks the result of the blackjack game, given the sum of all cards in player 1’s and player 2’s hand in each round. For the i-th round, the i-th index of player1 list represents the sum of all cards of player1, and the i-th index of player2 list represents player2's card sum. The i-th index of the returned list should be the winner's card sum. If both players' card sums go over 21 in...
use python to solve Write a function called word_chain that repeatedly asks the user for a...
use python to solve Write a function called word_chain that repeatedly asks the user for a word until either (1) the user has entered ten words, or (2) the user types nothing and presses enter. Each time the user enters an actual word, your program should print all the words entered so far, in one long chain. For example, if the user just typed "orange", and the user has already entered "apple" and "banana", your program should print "applebananaorange" before...
Using Python Question 1 Write an input function. Then use it to supply the input to...
Using Python Question 1 Write an input function. Then use it to supply the input to following additional functions: i) Print multiplication table of the number from 1 to 12. ii) Print the sum of all the numbers from 1 to up the number given. iii) Print if the number supplied is odd or even. Question 2 Write function that asks for input from a user. If the user types 'end', the program exits, otherwise it just keeps going.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT