These three Python projects for beginners use a marksheet, a short quiz and a daily expense log. Build them in order to practise input validation, loops and files. Each example runs from the terminal with Python 3 and uses the standard library.
Set up a folder and run your first script
Create a folder called python-practice and open it in your editor. Open the terminal in that folder and check python --version. On Windows, try py --version if the python command is unavailable. Save each code example in its own file, then use the run command shown below it. If your terminal uses py, replace python with py.
Project 1. Student marks calculator
Make a small marks calculator for a three-subject practice test. Enter a whole-number score out of 100 for each subject. The program keeps asking for the same subject when the input is invalid. It adds the valid scores and works out the overall percentage because each subject has the same maximum score.
Source code for marks.py
subjects = ["English", "Computer Science", "Mathematics"]
marks = []
for subject in subjects:
while True:
try:
score = int(input(f"{subject} marks (0–100): "))
if 0 <= score <= 100:
marks.append(score)
break
except ValueError:
pass
print("Enter a whole number from 0 to 100.")
total = sum(marks)
print(f"Total: {total}/{100 * len(subjects)}")
print(f"Percentage: {total / len(subjects):.2f}%")
Run python marks.py. Try 78, 86 and 92 and check for 256/300 and 85.33%. Enter 101 or eighty once and make sure the same question appears again.
Challenge Add a fourth subject and report which subject has the highest score. Check your output with two subjects tied for highest.
Project 2. Command-line coding quiz
Write a quiz to revise a few Python basics before an interview. Each question and answer are stored together in a tuple. The loop presents one question at a time, checks the response and gives feedback. Removing extra spaces and normalising letter case lets answers like LEN count as correct.
Source code for quiz.py
questions = [
("Which Python function counts items in a list?", "len"),
("Which keyword starts a function definition?", "def"),
("What does 7 % 3 return?", "1"),
]
score = 0
for question, correct in questions:
answer = input(question + " ").strip().casefold()
if answer == correct:
score += 1
print("Correct!")
else:
print(f"Answer: {correct}")
print(f"Score: {score}/{len(questions)}")
Run python quiz.py. Answer len, def and 1 for 3/3. Run it again with one wrong answer and confirm that the program shows the right answer and ends at 2/3.
Challenge Add questions on loops and dictionaries. Keep a list of missed questions so the learner can review them at the end.
Project 3. CSV expense tracker
Record one expense per run and store it in a CSV file. Each run keeps the earlier rows and reads them back to calculate the running total. The example uses Decimal to store rupee and paise amounts, with a practice limit of ten lakh rupees per entry. Try describing an expense with a comma, such as Lunch, college canteen, to see how the CSV writer keeps the description together.
Source code for expenses.py
import csv
from decimal import Decimal, InvalidOperation
from pathlib import Path
file_path = Path("expenses.csv")
description = input("Expense description: ").strip()
try:
amount = Decimal(input("Amount in rupees: ").strip())
valid = (
amount.is_finite()
and Decimal("0") < amount <= Decimal("1000000")
and amount.as_tuple().exponent >= -2
)
except InvalidOperation:
valid = False
if not description or not valid:
raise SystemExit("Enter a description and a positive amount with up to two decimals.")
new_file = not file_path.exists() or file_path.stat().st_size == 0
with file_path.open("a", newline="", encoding="utf-8") as file:
writer = csv.writer(file)
if new_file:
writer.writerow(["description", "amount"])
writer.writerow([description, f"{amount:.2f}"])
with file_path.open(newline="", encoding="utf-8") as file:
reader = csv.DictReader(file)
total = sum((Decimal(row["amount"]) for row in reader), Decimal("0"))
print(f"Saved {description}. Total expenses: Rs {total:.2f}")
Run python expenses.py twice. Enter Bus fare at 40.50 and Notebook at 65. With a fresh CSV file, the second run reports Rs 105.50. Check that expenses.csv has one header and two expense rows. Test a negative amount and confirm that the file still has two rows.
Challenge Add a category column and print a subtotal for travel, food and stationery. Try the new CSV layout with a fresh practice file. Python CSV documentation
Explain your project in an interview
Choose one script and explain the problem, a test input and one improvement. For the expense tracker, for example, show how you handle a negative amount and explain why you append a new row. Keep a short README with the run command and sample output. If you want feedback on your next program, explore Python training in Ambala.