Question: Imagine you forgot your 4 digit passcode for your phone, and you need to guess the correct passcode. 9:41 AM ***** 1 4 GHI


Imagine you forgot your 4 digit passcode for your phone, and you need to guess the correct passcode. 9:41 AM ***** 1 4 GHI 7 PORS Enter Passcode Emergency NL ) ( 00 2 3 ABC DEF 5 8 O 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. 1 4N34 in 6 2 7 8 8.10.8: Guess the Passcode 5 The passcode is randomly generated and stored in the variable secretPasscode. Print out how many guesses it took to guess the correct passcode. 9 10 import random 11 Write a program that guesses every possible 4 digit passcode combinations until the correct passcode is guessed. 12 # Checks whether the given guess passcode is the correct passcode 13 def is correct (guess_code, correct_code): 14 return guess_code == correct_code 19 20 - 21 15 16 # Generates a random 4 digit passcode and returns it as a String 17 def generate_random_passcode(): 18 random_passcode for i in range (4): = random_digit = random.randint(0, 9) random_passcode += str(random_digit) 22 23 24 25 secret_passcode = generate_random_passcode() 26 # Write your code here return random_passcode
Step by Step Solution
3.40 Rating (150 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
