54 fee reminders in one second with Python
Tuition teachers, shop owners and club organisers send the same message to dozens of people with only a name, an amount or a date changed. Copy, paste, edit, repeat.
Here you write the message once with placeholders, and Python fills them in for every person on the list. Edit the message below and press Run.
Write one message and Python personalises it for every student.
The Python behind it · 23 lines
1template = "Hi {name}, your fee of ₹{fee} is due on {date}. Thank you!" # use {name}, {fee}, {date}23# Your tuition batch, as it sits in a sheet4students = [5 ("Aarav", 2500, "05 Nov"), ("Diya", 3000, "05 Nov"), ("Kabir", 2500, "07 Nov"),6 ("Meera", 3500, "05 Nov"), ("Rohan", 2500, "10 Nov"), ("Sana", 3000, "07 Nov"),7] * 9 # 54 students89messages = []10try:11 for name, fee, date in students:12 messages.append(template.format(name=name, fee=f"{fee:,}", date=date))13except (KeyError, ValueError, IndexError) as problem:14 print(f"Check the {{ }} in your message: only {{name}}, {{fee}} and {{date}} work ({problem})")15 messages = []1617if messages:18 for m in messages[:3]:19 print("→", m)20 print(" ...")21 print(f"\n✓ {len(messages)} personal messages ready in under a second")22 print(f" Fees to collect: ₹{sum(f for _, f, _ in students):,}")23 print(" (Hook this to WhatsApp or email and they go out on their own.)")
How the code works, step by step
1.The list of people
Each student is (name, fee, due date). Multiplying the list by 9 turns 6 rows into 54, to show that the size of the list makes no difference to the code.
3# Your tuition batch, as it sits in a sheet4students = [5 ("Aarav", 2500, "05 Nov"), ("Diya", 3000, "05 Nov"), ("Kabir", 2500, "07 Nov"),6 ("Meera", 3500, "05 Nov"), ("Rohan", 2500, "10 Nov"), ("Sana", 3000, "07 Nov"),7] * 9 # 54 students2.Fill in the template
str.format replaces {name}, {fee} and {date} with the values for each student; {fee:,} adds the comma separator. If the message uses a placeholder the code does not know, the except block explains it instead of crashing.
9messages = []10try:11 for name, fee, date in students:12 messages.append(template.format(name=name, fee=f"{fee:,}", date=date))13except (KeyError, ValueError, IndexError) as problem:14 print(f"Check the {{ }} in your message: only {{name}}, {{fee}} and {{date}} work ({problem})")15 messages = []3.Show the result
The first three messages are printed as a preview, followed by the count and the total fees to collect.
17if messages:18 for m in messages[:3]:19 print("→", m)20 print(" ...")21 print(f"\n✓ {len(messages)} personal messages ready in under a second")22 print(f" Fees to collect: ₹{sum(f for _, f, _ in students):,}")23 print(" (Hook this to WhatsApp or email and they go out on their own.)")
Make it yours
- Read the list from a CSV of your students or customers.
- Send the messages by email with smtplib (on your own computer).
- Only remind people whose due date is in the next three days, using datetime.
Questions
- Can Python send these on WhatsApp?
- Yes, through the official WhatsApp Business API or a provider built on it. Avoid tools that automate WhatsApp Web, since WhatsApp can block numbers that use them. Email is the easiest place to start.
- What is the {fee:,} part?
- A format specification: the comma tells Python to add thousands separators, so 3000 prints as 3,000.