Question: CodeHS Python question - Guess the Passcode Imagine you forgot your 4 digit passcode for your phone, and you need to guess the correct passcode.

CodeHS Python question - Guess the Passcode

Imagine you forgot your 4 digit passcode for your phone, and you

need to guess the correct passcode. 4 GHI 7 PORS 9:41 AM

Imagine you forgot your 4 digit passcode for your phone, and you need to guess the correct passcode. 4 GHI 7 PORS 9:41 AM Enter Passcode 0000 Emergency 2 ABC 5 JKL 8 TUY O 3 DEF ( 6 MNO 9 WXYZ Cancel Write a program to guess passcodes for you that will speed up the process. The secret passcode has been randomly generated and is stored inside a variable called secret_passcode. Starting with 0000, guess every possible passcode all the way up to 9999. Once the correct passcode has been guessed, print out how many guesses it took to reach the correct one. Discuss the following questions with a partner: 1. How many possible passcodes will you need to guess before you ve guessed every possible passcode? 2. Why is this dangerous for the security of your phone? 3. Imagine a hacker had access to your phone and had written a program to guess every possible passcode until they had broken in. What defenses could we build in to the phone to keep this guess and check strategy from working? (What happens when you guess incorrectly over and over again?) 4. Can you think of any guessing strategies that might be faster than starting at 0000 and iterating all the way up to 9999? 1 2 NM & in 600 3 4 5 7 12 13 14 8.10.8: Guess the Passcode Write a program that guesses every possible 4 digit passcode combinations until the correct passcode is guessed. 8 Print out how many guesses it took to guess the correct passcode. 9 10 import random 11 22 23 24 The passcode is randomly generated and stored in the variable secretPasscode. # Checks whether the given guess passcode is the correct passcode def is correct (guess_code, correct_code): return guess_code == correct_code 15 16 # Generates a random 4 digit passcode and returns it as a String 17 def generate_random_passcode(): 18 19 20 - 21 random_passcode for i in range (4): random_digit = random.randint(0, 9) random_passcode += str(random_digit) return random_passcode 25 secret_passcode = generate_random_passcode() 26 # Write your code here

Step by Step Solution

3.39 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The python code wh... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!