Projects›Core· 90 min read
Project: Build a Python Program
Put it together into a small, real, interactive program.
What you will learn
- Combine variables, loops, functions and data
- Handle user input
- Build something complete
The brief
Build a small console program of your choice — a quiz, a to-do manager, a simple calculator, or a number-guessing game.
Example: number-guessing game
This little game ties together almost everything from the course — a module (random), a variable, a while loop, input, and if/elif decisions. The computer picks a secret number and the player keeps guessing until they get it.
import random
secret = random.randint(1, 10)
guess = 0
while guess != secret:
guess = int(input("Guess (1-10): "))
if guess < secret:
print("Too low")
elif guess > secret:
print("Too high")
print("Correct! 🎉")Here is the whole flow, step by step:
import randombrings in the random module so we can pick an unpredictable number.random.randint(1, 10)chooses a secret whole number from 1 to 10 and stores it insecret. We setguess = 0just so the loop has something to compare on the very first check.- The
while guess != secret:loop keeps repeating as long as the guess is not equal to the secret (!=means “not equal”). - Each turn,
int(input(...))asks the player for a number and converts their text into an integer. - The
if/elifthen compares: if the guess is too small it printsToo low, if too bigToo high. (If it is exactly right, neither runs — and the loop’s condition is now false.) - Once the guess matches, the loop ends and the final line prints the congratulations message.
Note: Output (one example run): Guess (1-10): 5 Too low Guess (1-10): 8 Too high Guess (1-10): 7 Correct! 🎉 (The secret changes every time you play, so your run will differ.)
Tip: Start simple, get it working, then add features (a score, a limit on guesses, play-again).
✍️ Practice
- Build the guessing game (or your own idea) and run it.
- Add a feature of your own.
🏠 Homework
- Build a console to-do app: add, list and remove tasks in a loop.