Question 1: Password checking
You are presented with a file passwords.txt
where each line contains an email address followed by a password. The email address is separated from the password by a comma.
Your job is to write a Python script (starting with the template lab6q1.py
) to flag all passwords that are not secure (or insecure).
A password is considered secure if it satisfies the following conditions:
- contains at least 8 characters,
- contains at least one numeric digit, and
- contains at least alphabet character.
Otherwise, a password is not secure.
Your Python script that will read in the file passwords.txt
and for each insecure password, print the following information: * the line number in the file * the email address * the password * condition(s) password failed to be secure
At the end, you should also print the number of email addresses with insecure passwords.
For example, suppose the file passwords.txt
contain the following lines:
[email protected],abc123[email protected],ay799dkZ![email protected],mrcool[email protected],12345789[email protected],ntyd888896[email protected],8739!
Then the output should look like:
Invalid Passwords Detail:1) [email protected],abc123:less than 8 characters3) [email protected],mrcool:less than 8 characters, no digit4) [email protected],12345789:no alphabet character6) [email protected],8739!:less than 8 characters, no alphabet characterThere were 4 emails with insecure passwords.
The file lab5q1.py
contains two functions hasNumbers(s)
and hasAlpha(s)
which returns True
if and only if s
has a digit and alphabet character, respectively.
Question 2: Deduction Game
Write a game where a user has to guess a number from 1 99.
Your program will generate a random number once (pick a number), and will then prompts the user to repeatedly guess the number until they get it correct.
During the game, your program will test the number that the user entered compared to the number it picked. If the number that the user guessed is greater than the random number, tell the user your guess is too low. If the number that the user guessed is higher than the random number, tell the user, your guess is too high. Let the user continue guessing the number generated until they guess it right.
Once the user has successfully guessed the number, tell the user they win, and tell them how many guesses it took them to guess it right.
Use a loop to check your user input. Use strings .isnumeric() to check to see if the user has provided you with a valid number before you use a cast to an integer. Your program should not crash if the user gives you bad input.
To create a random number use:
Sample game:
I've picked a number between 1 and 99, can you guess it? 50Nope, it's not 50Your guess is too lowI've picked a number between 1 and 99, can you guess it? 99Nope, it's not 99Your guess is too highI've picked a number between 1 and 99, can you guess it? 42Nope, it's not 42Your guess is too lowI've picked a number between 1 and 99, can you guess it? 93Nope, it's not 93Your guess is too highI've picked a number between 1 and 99, can you guess it? 83You got it!It took you 5 guesses.
Optional: New and Improved Deduction Game
Once youve completed the guessing game, add some usability improvements. In the line that prompts the user for input, print the known range the random number could be in.
Do not increase the range if the user guesses outside your range. Example, if the current range is 40 to 60, do not change them if the user guesses 100.
Example:
Guess the number. 0 < _ < 100: 50Guess the number. 0 < _ < 50: 25Guess the number. 0 < _ < 25: 12Guess the number. 12 < _ < 25: 18Guess the number. 12 < _ < 18: 14Guess the number. 14 < _ < 18: 16Guess the number. 16 < _ < 18: 17Congrats you guessed it in 7 tries
Challenge: Whats the fewest number of guesses you have to make for any range of numbers? Hint: This is a search algorithm called a binary search.
Rate this product
Reviews
There are no reviews yet.