Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
0
Indexable
Never
Awesome! Let's get started with the game. We'll create a simple Python script for this text-based ball game. Here's the code:

```python
import random

def ball_game(level):
    score = 0
    target_score = 10 if level == 'easy' else 20 if level == 'medium' else 30 if level == 'hard' else 0

    while score < target_score:
        print(f"Current Score: {score} | Target Score: {target_score}")
        user_input = input("Choose a number between 1 to 5: ")

        if not user_input.isdigit() or int(user_input) < 1 or int(user_input) > 5:
            print("Invalid input. Please choose a number between 1 to 5.")
            continue

        ball_number = random.randint(1, 5)
        print(f"The ball landed on: {ball_number}")

        if int(user_input) == ball_number:
            print("Congratulations! You scored a point!")
            score += 1
        else:
            print("Oops! Try again.")

    print(f"Congratulations! You reached the target score of {target_score}. Game Over!")

if __name__ == "__main__":
    print("Welcome to the Ball Game!")
    level = input("Choose your level (easy, medium, hard): ")
    ball_game(level)
```

Copy and paste this code into a Python environment (Python 3.x recommended) and run it. The game will prompt you to choose a level (easy, medium, or hard) and then ask you to input a number between 1 to 5.

Remember, the game's target scores are 10 for easy, 20 for medium, and 30 for hard. The player wins when they reach the target score for the chosen level.

Enjoy playing the game, and if you have any questions or modifications, feel free to let me know!