In: Computer Science
Instructions
Complete the program below. The program should be turned in as a .py file. Please turn in the .py file itself (do not take a picture of it or copy/paste it into another program). Please also turn in the output for your program. The output should be in a different file. You may find the easiest way is to take a screenshot of your output. You can use the snipping tool on Windows or the grab tool on a Mac to take pictures of your output. You may want to put all of your output pictures in a single Word file.
Criteria for Success
Please view the rubric to ensure you are completing everything you need. You are required to use functions. In addition, make sure the output examples you turn in show a variety of test cases. You can create a test() function in your program to prove the majority of your code works.
Password Validator
When users create a new account on a website, they are often asked to create a new password. Many websites then test the password to make sure it is strong enough before allowing a user to save it. If it's not strong enough, the user needs to create a new password.
In this program, you will ask a user for a username/password combination and test for password strength according to the following rules:
Your program will prompt for a username. Then, it will prompt for a password. Your program should check the password. If the password is OK, print "Good Password!" and end the program. If the password is NOT OK, print the appropriate message to the user. Continue reprompting until the user successfully picks a good password.
If there are multiple problems with the password, you only need to report one.
Consider: Is this the most user-friendly approach?
No. It's not. But it does seem some websites continue to hassle the user this way, while others let the user know up front what is expected... And give better error messages than these, often reincluding what is required. I prefer those sites. However, I want you to write the code that can give specific errors.
Obvious Password
Rule: If a password contains 1 or more of the following Strings (ignore case):
Message to user: Don't use common passwords
Too Short Password
Rule: Password must be at least 8 characters long
Message to user: Password must be at least 8 characters long
Too Long Password
Rule: Password must be less than 21 characters long
Message to user: Password must be less than 21 characters
Low Complexity Password
Rule: The password must contain at least 1 character each of:
Message to user: Passwords must contain both upper and lower case letters, at least one digit and at least one punctuation mark (!+.@$%*)
Unrecognized Character
Rule: Your company's back-end systems don't like certain characters. Therefore, the password must only contain:
Message to user: Password contains an Invalid Character
Other Issues
Rule: If the password has one of the following issues, alert the user of the issue and have them choose a new one.
Message to User: Passwords can't contain a variation of the username
Pig Latin Translator
Write a program that asks the user for a sentence and converts it to Pig Latin. The below explains how to convert to Pig Latin:
If the first letter is a vowel (a, e, i, o, u):
If the first letter is a consonant (treat the letter "y" as a consonant):
Words that have their first letter capitalized, should continue to have the (possibly new) first letter capitalized.
Sentences end with a period (.), an exclamation point (!) or a question mark (?). Make sure the punctuation continues to stay at the end of the sentence.
English | Pig Latin |
sleep | leepsay |
the | hetay |
python | ythonpay |
computer | omputercay |
pig | igpay |
Latin | Atinlay |
if | ifway |
other | otherway |
only | onlyway |
apple | appleway |
Sentences occassionally have other punctuation such as commas (,) and semicolons (;). Make sure these punctuation marks stay put.
For example:
Original sentence: Hello World!
Right: Ellohay orldway!
NOT: elloHay orld!Way
Original sentence: To be, or not to be?
Right: Otay ebay, orway otnay otay ebay?
NOT: oTay e,bay orway otay e?bay
You only have to deal with the 5 punctuation marks mentioned (. ! ? , ;)
***Please upvote/thumbsup if you liked the answer***
PigLatinCalculator:-
Screenshot of the Python code:-
Output:-
Python code to copy:-
VOWELS = ['a','e','i','o','u'];
PUNCTUATIONS = ['.' ,'!' ,'?' , ';'];
def ConvertWordToPigLatin(word):
flag = False
for v in VOWELS:
if(word[0:1] == v):
if (word[len(word) - 1] not in PUNCTUATIONS):
word = word + "way"
flag = True
break
else:
word = word[0:len(word) - 2] + "way" + word[len(word) - 1]
flag = True
break
if(bool(flag) == False):
if (word[len(word) - 1] not in PUNCTUATIONS):
word = word[1:] + word[0:1] + "ay"
else:
word = word[1:len(word) - 1]+ word[0:1] + "ay" + word[len(word) -
1]
return word
sentence = input("Enter sentence");
if (sentence[0:1].isupper()):
flag = True
else:
flag = False
sentence = sentence.lower()
word_arr = sentence.split(" ")
piglatinarr = []
for word in word_arr:
piglatinarr.append(ConvertWordToPigLatin(word))
if flag == True:
piglatinarr[0] = piglatinarr[0][0].capitalize() +
piglatinarr[0][1:]
print(" ".join(piglatinarr))