Question

We are trying to make sure your passphrase is acceptable! Write a script that asks for...

We are trying to make sure your passphrase is acceptable! Write a script that asks for an input string that will be used as your password. This input string will have three “words” separated by a space character. Each of these words has specific requirements, listed below. You must write a function for each requirement (three total functions). Make sure your functions follow the original template that provided.

First Function: For the first word, you must check if it is a palindrome (it is the same forward and backward, like "glolg" or "tacocat"), is case-insensitive (so "GfraaRFg" or "VObov" are valid), and only uses alphabetical letters ("tre3ert" and “f^h,@s@,h^f” are not valid).

Second Function: For the second word, you must check if it is a positive integer with at least 4 digits, containing only numeric characters (i.e. no alphabetic, punctuation, or special characters).

Third Function: For the third word, you must check if it starts with one of these special characters (“​@​”, “​$​”, “​%​”, “​^​”, “​&​”), ends with a punctuation mark (only commas ("​,​"), periods ("​.​"), exclamation marks (“​!​”) and question marks ("​?​") are allowed), and has three letters in between the special character and punctuation mark (e.g. “​@dog!​” or “​$tpb?​” or “​^cat,​”).

If the entire password meets all the correct specifications, then print “valid”; otherwise, print “invalid”.

Template Functions ​(DO NOT CHANGE FUNCTION NAMES)​:

def palindrome():

def integer():

def special():

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

def palindrome(x):

  x = x.lower()

  x1 = x[::-1]

  if x.isalpha() and x == x1:

    return True

  else:

    return False  

def integer(x):

  if x.isdigit() and len(x)>=4:

    return True

  else:

    return False        

def special(x):

  n = len(x)

  special = '@$%^&'   

  punc = ',.!?'

  if (x[0] in special) and (x[n-1] in punc) and (len(x)==5):

    return True

  else:

    return False  


x,y,z = input().split(" ")

if palindrome(x) and integer(y) and special(z):

  print('valid')

else:

  print('invalid')  

Add a comment
Know the answer?
Add Answer to:
We are trying to make sure your passphrase is acceptable! Write a script that asks for...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 8.4 in python function that checks whether a string is a valid password. Suppose the pas...

    8.4 in python function that checks whether a string is a valid password. Suppose the pas rules are as follows: . A password must have at least eight characters - A password must consist of only letters and digits. ■ A password must contain at least two digits. Write a program that prompts the user to enter a password and displays valid password if the rules are followed or invalid password otherwise (Occurrences of a specified character) Write a function...

  • Can you help me make these two methods listed below work? I have code written but...

    Can you help me make these two methods listed below work? I have code written but it is not working. I would appreciate any advice or help. Function "isAPalidrome" accepts an array of characters and returns an integer. You must use pointer operations only, no arrays. This function should return 1 (true) if the parameter 'string' is a palindrome, or 0 (false) if 'string' is not a palindrome. A palindrome is a sequence of characters which when reversed, is the...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

  • Write a PowerShell script. Make sure to: Comment your script by including your name, date, and...

    Write a PowerShell script. Make sure to: Comment your script by including your name, date, and short description what the script does The script receives two arguments/parameters, first one should be a string and the second one an integer number. Both should be passed to the script as (positional) arguments/parameters Check if there are two passed parameters Check if passed parameters are as expected (check if first is string and secondis integer). You can use param() here. Displays on the...

  • Palindrome is a word or a phrase when taken in reverse order, gives the same word...

    Palindrome is a word or a phrase when taken in reverse order, gives the same word or phrase. For example, the word “radar” is a palindrome. The phrase "Do geese see God?" is also a palindrome after the removal of the question mark and all the spaces and the conversion of the remaining alphabets to either upper or lower case. Write a program that uses an STL stack to check if an arbitrary string containing multiple words separated by spaces...

  • I need help programming this program in C. 1.) Write a program that reads a message,...

    I need help programming this program in C. 1.) Write a program that reads a message, then checks whether it's a palindrome (the letters in the message are the same from left to right as from right to left), example is shown below: Enter a message: He lived as a devil, eh? Palindrome Enter a message: Madam, I am Adam. Not a Palindrome 2.) Ignore all characters that aren't letters. Use integer variables to keep track of positions in the...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • 2. This question is about processing strings 2.1 [4 marks] Given a string str, we can...

    2. This question is about processing strings 2.1 [4 marks] Given a string str, we can calculate a checksum of the string by summing up the ASCII codes of the characters in the string. For example, the checksum of a string "apple" is 530, which equals to 'a' + 'p' + 'p' + 'l' + 'e' = 97 + 112 + 112 + 108 + 101. Write a function int calculate_checksum(char str[] that calculates and returns the checksum of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT