Question

In: Computer Science

Task 1: Some websites impose certain rules for passwords. Write a program that ask the user...

Task 1:

Some websites impose certain rules for passwords. Write a program that ask the user to enter a password and checks whether a string

(Use input validation to make sure the user enters the correct password and then print it.)

is a valid password. Suppose the password rules are as follows:

• A password must have list a least 10 characters.

• A password must consist of only letters and digits.

• A password must contain at least two digits.

• A password must have at least one uppercase letter.

• A password must have one of the following characters: #, $, &, @, &, %

Example of valid passwords:

Col11egeOfDupag3$

CIS2531Course@cod

Pyth0n&1CODclass

Example of invalid passwords:

myid#COD

CIS2531CollegeOfDupage

Abc123

Task 2:

Reads a string from the user containing a date in the form 03/12/2020 and the program will

display the date in the form March 12, 2020.

Please use comments to explain your work so I can understand it, Thanks

Solutions

Expert Solution

Task 1: Making use of regex will help us to achieve the required result.

reg = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d.*\\d)(?=.*[@$%#&])[A-Za-z\d@$#%&]{10,}$"

^ represents start of string

?=.*[a-z] represents the positive lookahead with zero or more occurrence of a - z

?=.*[A-Z] represents the positive lookahead with zero or more occurrence of A - Z i.e at least one uppercase letter

?=.*\\d.*\\d represents the positive lookahead with atleast 2 digits

?=.*[@$%#&] represents the positive lookahead with zero or more occurrence of the special characters @,$,%,#,&

[A-Za-z\d@$#%&]{10,} represents the password should contain at least 10 characters of these

$ represents the end of the string.

def validate_password(password):
    #this regex will validate the password meeting the requirements
    #^ denotes the start, $ denotes the end, ?= positive lookahead, * zero or more occurences,\\d\\d the digits for atleast 2 times and {10,} password atleast 10 characters
    reg = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d.*\\d)(?=.*[@$%#&])[A-Za-z\d@$#%&]{10,}$"
    pattern = re.compile(reg)  #compile the regex                 
    match = re.match(pattern, password)   #if there is a match, it returns matched re object
    # validating conditions 
    if match: 
        return True #return True if match
    else:
        return False #else return False
#password=input("Please enter password")
#print(validate_password(password))
print(validate_password("Col11egeOfDupag3$")) #validate the password

Output: True

Task 2: Reads a string from the user containing a date in the form 03/12/2020 and the program will

display the date in the form March 12, 2020.

  • split the string into list making use of delimiter '/'.
  • convert string to datetime object. since the list is of type str, convert them into int.
  • convert the datetime object to this format. %B gives us full month name, %d gives day and %Y gives year.
date_string="12/3/2020" #input string
date_string=date_string.split("/") #split the string into list making use of delimiter '/'
dt = datetime(year=int(date_string[2]), month=int(date_string[1]), day=int(date_string[0])) #convert string to datetime object. since the list is of type str, convert them into int
dt = datetime.strftime(dt,'%B %d, %Y') #convert the datetime object to this format. %B gives us full month name, %d gives day and %Y gives year
print(dt)

Output:

March 12, 2020


I am also attaching the output and code screenshots.

Output and code screenshot:

#Please don't forget to upvote if you find the solution helpful. Feel free to ask doubts if any, in the comments section. Thank you.



Related Solutions

Task 1. creating a nested if:   Need a python program that ask the user to enter...
Task 1. creating a nested if:   Need a python program that ask the user to enter the annual income of an employee and the years of experience. Pass these data to a function. The function decides if an employee does qualify for a loan or does not, then it prints a message based on the following rules: If the income is equal or greater than $40000, the function checks if the employee's years of experience is greater than 4, if...
1. Write a program that will ask the user to enter a character and then classify...
1. Write a program that will ask the user to enter a character and then classify the character as one of the following using only IF-ELSE and logical operators. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • Integer • Lower Case Vowel • Upper Case Vowel • Lower Case Consonant • Upper Case Consonant • Special Character
Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
Task 2.5: Write a script that will ask the user for to input a file name...
Task 2.5: Write a script that will ask the user for to input a file name and then create the file and echo to the screen that the file name inputted had been created 1. Open a new file script creafile.sh using vi editor # vi creafile.sh 2. Type the following lines #!/bin/bash echo ‘enter a file name: ‘ read FILENAME touch $FILENAME echo “$FILENAME has been created” 3. Add the execute permission 4. Run the script #./creafile.sh 5. Enter...
Write a program that does the following. It will ask the user to enter an integer...
Write a program that does the following. It will ask the user to enter an integer larger than 1, and the if entered integer is not larger than 1, it keeps prompting the user. After the user enters a valid integer, the program prints all the prime factors of the integer (including the repeated factors). For example, if the entered integer is 24, the program prints: 2 2 2 3 Run your program with the test cases where the entered...
Write a program will ask the user for the annual income and the number of years...
Write a program will ask the user for the annual income and the number of years that the user has worked as their current job. The program will tell the user whether or not he or she qualifies for a loan based on the following condition: income is equal to or exceeds $35,000 or number of years on job is greater than 5 Do not use “nested if statements” in your solution. As an example of the output: What is...
In python. Projectile motion: Write a python program that will ask the user for      an...
In python. Projectile motion: Write a python program that will ask the user for      an initial height y0, initial velocity v, launch angle theta, and mass m.      Create two functions, one that will calculate max height      of the projectile, and one that will calculate the range. Ask the     user which one he/she would like to calculate, then present them with the answer. (use kg, m and m/s)
Calculating Delivery Cost Program in Python write a program in Python that will ask a user...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user to enter the purchase total, the number of the items that need to be delivered and delivery day. Then the system displays the cost of delivery along with the total cost. Purchase total > $150 Yes Number of the items (N) N<=5 N>=6 Delivery day Same Day Next Day Same Day Next Day Delivery charges ($) 8 N * 1.50 N * 2.50 N...
write a program i java that ask the user to enter salary, user ID and username...
write a program i java that ask the user to enter salary, user ID and username and out put them
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT