CodeHS Python question - Guess the Passcode Imagine you forgot your 4 digit passcode for your phone,
Fantastic news! We've Found the answer you've been seeking!
Question:
CodeHS Python question - Guess the Passcode
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Introduction To Probability And Statistics
ISBN: 9780495389538
13th Edition
Authors: William Mendenhall, Robert J. Beaver, Barbara M. Beaver
Posted Date:
Students also viewed these programming questions
-
Question 1 1.1 You have an empty stack in which you perform the following sequence of operations: push ("customer 1") push ("customer 2") pop() push ("customer 3") peek() provide a visual description...
-
: Write code in the next cell to do the following: 1. Asks the user for their first, middle, and last names and stores each in a new variable. 2. Computes the length of the name not including spaces...
-
3.This question assesses your knowledge of functions: a.Write a Python function to sum all the numbers passed to it in a list. [44, 33, 22, 11] b.Write a Python function that takes the result of 3a...
-
) A local firm employs 20 full-time professionals. The budgetedannual compensation per employee is $81,000. The budgeted averagechargeable time is 500 hours per client annually. All professionallab 2...
-
Prepare the necessary entries from 1/1/10-2/1/12 for the following events using the fair value method. If no entry is needed, write "No Entry Necessary." 1. On 1/1/10, the stockholders adopted a...
-
Lita Lopez started Biz Consulting, a new business, and completed the following transactions during its first year of operations. a. Lita Lopez invested $70,000 cash and office equipment valued at...
-
This problem helps you develop skill in recording transactions by using a companys actual account titles. Refer to the Amazon.com financial statements in Appendix A. Assume that Amazon.com completed...
-
Gourmet Helper Appliance Company manufactures home kitchen appliances. The manufacturing process includes stamping, final assembly, testing, and shipping. In the stamping operation, a number of...
-
1.To address Uncle Pete's issue of needing to paint boat bottoms every spring, determine the cost of hiring two additional full-time workers. 2.What factors other than cost should be considered in...
-
On December 31, Y3, Aylmer Industries Inc. purchased 85% of the outstanding shares of Belmont Inc. The purchase price is indicated on the excel file. The entry has been recorded on the books of...
-
Consider the following reaction: 2 P(e) + 3 H2) 2 PH3(2) (assume P) is white P) a) Use tabulated data in the text to calculate K, for this reaction at 298 K. b) Use tabulated data in the text to...
-
This assignment will require you to analyze time series of monthly returns. Start by retrieving MONTHLY data for the period of 01/01/2016 - 12/31/2021 from Yahoo website for S&P 500 Index (ticker:...
-
Jake just quit his job as a shoe salesman and is looking for work as an accountant, which is what his college degree is in. Jake would be considered?
-
Explain using illustrations, how we resolved the deadlock (Read commitment) in KPN models using Synchronous data flow models? (20 points). Q5:> Embedded System Design SDF (20 points): A B 2 3 C Q1:A>...
-
If constructivism aims to provide context for learning, how can teachers provide context for very young students who do not have a framework for learning? Provide an example.
-
Morty drags Rick's unconscious body 50 meters along a flat surface. Morty applies a force of 30N at an angle of 40 above the horizontal. Find the work done by the force exerted by Morty
-
Adrian invested $ 1 0 0 at the end of every month into an RRSP for 1 3 years. If the RRSP was growing at 5 . 2 0 % compounded quarterly, how much did she have in the RRSP at the end of the 1 3 - year...
-
The area of a rectangle is 30 cm 2 and its perimeter is 26 cm. Find the length and width of the rectangle.
-
The makers of the Lexus automobile have steadily increased their sales since their U.S. launch in 1989. However, the rate of increase changed in 1996 when Lexus introduced a line of trucks. The sales...
-
Who are the men and women who serve in our armed forces? Are they male or female, officers or enlisted? What is their ethnic origin and their average age? An article in Time magazine provided some...
-
Consider a Poisson random variable with μ = 2.5. Calculate the following probabilities using the following table. Calculated Value Probability Formula P(x = 0) k! P(x = 1) k! P(x = 2)...
-
Discuss the approach you would take to building a system for playing Scrabble or another word game of the sort. What limitations does your system have? How likely do you think it is that your system...
-
Discuss the current state of the art of game-playing computer systems in relation to the following games: chess, checkers, Go, bridge, Othello, tic-tac-toe. What advances are likely in the near...
-
Show the steps that would be taken in running the Minimax algorithm on the game tree in Figure 6.7. Now run through the same tree using alpha-beta pruning. How do the two compare? data from figure...
Study smarter with the SolutionInn App