Write a Python program to implement the Code Cracking Game i The program randomly generates a 5

Write a Python program to implement the Code Cracking Game: i. The program randomly generates a 5-digit code with each digit being 0-9 without repetition. (Hint: Use the function randint().) ii. This secret code is always hidden from the user. iii. The user keeps guessing the secret code by entering 5 digits until she guesses the code correctly. iv. After each guessing, the program gives a hint to the user, which is constructed in the following way: if the user guesses both the digit and its position correctly then she gets one "P"; if she guesses only the digit correctly but not its position then she gets one "D". The hint is written in the form of "mPnD", where m and n are the total number of P's and D's, respectively, the user gets. For example, suppose the secret code is "03491" and the user's guess is "23974". Then the hint is "1P2D".

Write a Python program to implement the Code Cracking Game:

i. The program randomly generates a 5-digit code with each digit being 0-9 without repetition. (Hint: Use the function randint().)

ii. This secret code is always hidden from the user.

iii. The user keeps guessing the secret code by entering 5 digits until she guesses the code correctly.

iv. After each guessing, the program gives a hint to the user, which is constructed in the following way: if the user guesses both the digit and its position correctly then she gets one “P”; if she guesses only the digit correctly but not its position then she gets one “D”. The hint is written in the form of “mPnD”, where m and n are the total number of P’s and D’s, respectively, the user gets. For example, suppose the secret code is “03491” and the user’s guess is “23974”. Then the hint is “1P2D”.


 
Solved By Verified
Study Co-Pilot All Study Co-Pilots are evaluated by Gotit Pro as an expert in their subject area.

 
Instant
Download

Student review: (5 ratings) 5 out of 5 people found this solution helpful.