Aug-12-2024, 03:56 AM

Here is my homework:

Write a Python program that simulates a number guessing game. The computer will randomly generate a number between 1 and 100. The player will then have a limited number of attempts (e.g., 10) to guess the number. After each guess, the computer should provide feedback, indicating whether the guess is too high, too low, or correct.

Additional Requirements:

Use a loop to control the number of attempts.

Implement a function to check the guess against the random number and provide feedback.

Consider adding features like difficulty levels (adjusting the number range and maximum attempts) or keeping track of the number of guesses.

Below are my answer:

Implementing different difficulty levels.

Keeping track of the number of guesses it takes to win.

Making the game more user-friendly with informative messages.

Any suggestions or improvements would be greatly appreciated!

Retro Bowl College

Write a Python program that simulates a number guessing game. The computer will randomly generate a number between 1 and 100. The player will then have a limited number of attempts (e.g., 10) to guess the number. After each guess, the computer should provide feedback, indicating whether the guess is too high, too low, or correct.

Additional Requirements:

Use a loop to control the number of attempts.

Implement a function to check the guess against the random number and provide feedback.

Consider adding features like difficulty levels (adjusting the number range and maximum attempts) or keeping track of the number of guesses.

Below are my answer:

import random def guess_number(): random_number = random.randint(1, 100) attempts = 10 while attempts > 0: guess = int(input("Guess a number between 1 and 100: ")) if guess == random_number: print("Congratulations! You guessed the number in", 10 - attempts + 1, "attempts.") break elif guess < random_number: print("Too low.") else: print("Too high.") attempts -= 1 if attempts == 0: print("Sorry, you ran out of attempts. The number was", random_number) guess_number()I'm having trouble with:

Implementing different difficulty levels.

Keeping track of the number of guesses it takes to win.

Making the game more user-friendly with informative messages.

Any suggestions or improvements would be greatly appreciated!

Retro Bowl College