A simple command-line game where the program picks a random number and the player tries to guess it within a limited number of attempts. The game teaches basic input handling, loops, conditionals and using Python’s random module.
- The program selects a random integer (commonly from 1 to 100).
- The player inputs guesses and the program responds whether the guess is too low, too high, or correct.
- The player keeps guessing until they find the number or run out of attempts; the final score or number of attempts is shown.
Main script: random_no_guessing_game.py
import random
answer = random.randint(1, 100)
tries = 0
while True:
guess = int(input('Enter your guess (1-100): '))
tries += 1
if guess == answer:
print(f'Correct! You guessed in {tries} tries.')
break
elif guess < answer:
print('Too low, try again.')
else:
print('Too high, try again.')- Run:
python random_no_guessing_game.py - Enter guesses when prompted.
Friendly beginner project that reinforces control flow and randomness concepts. Try adding difficulty levels, attempt limits, or a high-score tracker as enhancements.