Ask Question
15 June, 04:56

Write a program for a simple game of guessing at a secret five-digit code. When the user enters a guess at the code, the program returns two values: the number of digits in the guess that are in the correct position and the sum of those digits. For example, if the secret code is 53840, and the user guesses 83241, the digits 3 and 4.

+5
Answers (1)
  1. 15 June, 05:53
    0
    from random import randint

    winner = False

    number = str (randint (10000, 99999))

    while (not winner):

    correct = 0

    total = 0

    guess = input ()

    if (number==guess):

    winner = True

    else:

    for i in range (5):

    if (number[i] = = guess[i]):

    correct+=1

    total+=int (number[i])

    print ('Correct: ' + str (correct))

    print ('Total: ' + str (total))

    print ('Winner')

    Explanation:

    I'm gonna show a solution in python 3

    Step 1 import library for generate random number

    from random import randint

    Step 2 create necesary variables to get the number and if the player is winner or not

    winner = False

    number = str (randint (10000, 99999))

    Step 3 loop while the player is not the winner

    while (not winner):

    Step 4 get the player guess number

    guess = input ()

    Step 5 validate if the player win

    if (number==guess):

    winner = True

    Step 6 if the player is not winner review what numbers are in the correct position

    for i in range (5):

    if (number[i] = = guess[i]):

    correct+=1

    total+=int (number[i])

    Step 7 print the hint

    print ('Correct: ' + str (correct))

    print ('Total: ' + str (total))
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program for a simple game of guessing at a secret five-digit code. When the user enters a guess at the code, the program returns ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers