total_games_played = 0
total_guesses = 0
while True:
print(‘Welcome to the guessing game!’)
print(‘I am thinking of a number between 1 and 10.’)
# Get user input
user_guess = int(input(‘What is your guess? ‘))
# Check if user guessed correctly
from random import randint
if user_guess == randint(1, 10):
print(‘You guessed correctly!’)
break
else:
print(‘That is not correct. Guess again!’)
# Check if user has ran out of guesses
if total_guesses == 10:
print(‘You ran out of guesses.’)
break
# Increment counters
total_games_played += 1
total_guesses += 1
# Calculate average number of guesses
avg_guesses = total_guesses / total_games_played
# Print results
print(‘Games played:’, total_games_played)
print(‘Total guesses:’, total_guesses)
print(‘Average guesses per game:’, avg_guesses)
# Ask user if they want to play again
play_again = input(‘Do you want to play again? (y/n) ‘)
# Check if user wants to play again
if play_again.lower() == ‘y’:
continue
else:
break