Untitled
unknown
plain_text
a year ago
1.1 kB
4
Indexable
Certainly! Here's a simple example of a text-based Python game. This is a guessing game where the player has to guess a randomly generated number. ```python import random def guess_the_number(): print("Welcome to the Guess the Number Game!") print("I have selected a random number between 1 and 100.") secret_number = random.randint(1, 100) attempts = 0 while True: guess = int(input("Take a guess: ")) attempts += 1 if guess == secret_number: print(f"Congratulations! You guessed the correct number in {attempts} attempts.") break elif guess < secret_number: print("Too low. Try again.") else: print("Too high. Try again.") if __name__ == "__main__": guess_the_number() ``` Copy and paste this code into a Python environment, and run the script. The player will be prompted to guess the randomly generated number, and the game will provide feedback if the guess is too high or too low. The game continues until the player correctly guesses the number.
Editor is loading...
Leave a Comment