Generation

generate functionTue, 18 Jul 2023

In this project you will create a numeric version of the game wordle. Instead of having a user guess a 5 letter word – you will have the user guess a 4 digit number. After each guess, you will output clues for the user for each digit in the guess. For each digit, the clue will be one of the following: • Sum • Difference (secret digit minus guess digit) • Product Whether you provide the sum, difference or product is randomly generated. Example 1 Suppose the secret number was 8651 and the user’s guess was 4523. Then the clue given after the guess might look like this: The sum of the first digits is 12. The product of the second digits is 30. The product of the third digits is 10. The difference of the fourth digits is -2. Example 2 Suppose the secret number was 1221 and the user’s guess was 4123. Then the clue given after the guess might look like this: The difference of the first digits is -3. The sum of the second digits is 3. The difference of the third digits is 0. The product of the fourth digits is 3. The user will only have 2 guesses. Level 3 Criteria Level 4 Criteria Secret number is at least 4 digits. All test cases pass. User can choose different levels of the game. Each level corresponds with a different number of digits. Secret number has no repeating digits. Program should handle unexpected input. If a user enters an unexpected input (not the correct length or does not contain all numbers), program should ask user to enter guess again until guess is the correct format. All test cases pass

print("Welcome to the Number Guessing game") import random #generate a random number with the same length as the level def generate_secret_number(level): secretNumber = "" for n in range(level): rand = random.randint(0, 9) secretNumber += str(rand) return secretNumber #check if the guess is correct def check(secretNumber, guess): if guess == secretNumber: return True else: return False #check if the guess is correct def check(secretNumber, guess): if guess == secretNumber: return True else: return False #generate feedback for the user def givefeedback(secretNumber, guess): feedback = "" for n in range(len(secretNumber)): if guess[n] == secretNumber[n]: feedback += "correct " else: feedback += "wrong " return feedback #run the game def run(): level = int(input("Select

Questions about programming?Chat with your personal AI assistant