Ask Question
26 August, 08:17

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.

+2
Answers (1)
  1. 26 August, 11:05
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers