Lesson 5 · Python for Data Science
5 - Automating Repetitive Tasks in Python
Ever get bored copying data, renaming files, or sending the same messages over and over? Today, you will learn how Python can help save you time by…
- CoursePython for Data Science
- Lesson5 of 38
- Video13 min
- FormatJupyter notebook · 24 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynb
Welcome to Automating Repetitive Tasks in Python!#
Ever get bored copying data, renaming files, or sending the same messages over and over?
Today, you will learn how Python can help save you time by automating these boring, repetitive tasks.
You do not need to be a programmer yetyou just need curiosity.
Let's begin our automation adventure!
# First, let's print a welcome message automatically.
print("Welcome, human! Did you know you can automate this message?")
Why Automate?#
Automation means computers do small, repeatable chores for us.
It saves time, reduces mistakes, and lets us focus on fun or important stuff.
You can use automation for:
- Renaming lots of files
- Sending reminders
- Filling out forms
Lets see basic Python tricks for these tasks.
# Loops let us do a task many times automatically.
for i in range(5):
print("Repeating message #", i + 1)
# Instead of sending five messages, let's automate sending messages to multiple friends.
friends = ["Eva", "Sam", "Luca"]
for name in friends:
print("Hi,", name, "- this is your reminder to drink water!")
How Input Helps Automation#
Python can ask you for information, then use it many times.
Input is a way to interact with your script.
Lets try it below.
# Let's ask for your favorite snack, then repeat a reminder.
snack = input("What is your favorite snack? ")
for i in range(3):
print("Don't forget to enjoy some", snack, "today!")
# With automation, tiny changes make a big difference.
# Here, we send personalized reminders for each friend.
for name in friends:
print("Hey", name + ",")
print("Don't forget to eat your", snack, "today!")
print()
Automating Repetitive Math#
What if you have a list of numbers and want to add the same bonus to each one?
Let Python do it!
# Suppose these are daily steps counted by your fitness tracker.
steps = [4900, 5200, 4800, 5000, 5300]
# Let's add a 500-step bonus to each day automatically.
steps_with_bonus = []
for count in steps:
steps_with_bonus.append(count + 500)
print("With bonus:", steps_with_bonus)
# Sometimes, the task is to pick only certain items.
# For example, finding step counts above 5000.
active_days = []
for count in steps:
if count > 5000:
active_days.append(count)
print("Days over 5000 steps:", active_days)
Safely Accessing Data#
Sometimes, data might be missing.
Python can help you avoid errors when something is not there.
Lets see a safe access pattern.
# Let's avoid errors if a friend is missing from the list.
search = input("Which friend's reminder are you looking for? ")
if search in friends:
print("Found! Sending a reminder to", search)
else:
print("Sorry, friend not found. Add them to the list first.")
# Lets learn to add and remove people from your friends list.
friends.append("Maya") # Adding Maya
print("Added Maya:", friends)
friends.remove("Eva") # Removing Eva
print("After removing Eva:", friends)
Using Built-in Functions to Automate Better#
Python comes with handy functions to save you even more time.
Lets use len() to count things, and sorted() to put them in order.
# How many friends do we have?
print("Number of friends:", len(friends))
# Let's see our friends alphabetically.
print("Sorted friends:", sorted(friends))
# Sometimes you want a summarythe total steps you walked.
print("Total steps:", sum(steps))
Automation With Comprehensions#
Comprehensions make short, powerful automation.
They create new lists from old lists in one line.
Try one example below.
# Double your daily steps using a list comprehension!
doubled_steps = [n * 2 for n in steps]
print("Doubled steps:", doubled_steps)
# You can use comprehensions to filter, too.
even_steps = [n for n in steps if n % 2 == 0]
print("Even step days:", even_steps)
# Mini-project: Automate birthday wishes for friends.
birthdays = {"Luca": "June 2", "Sam": "April 10", "Maya": "December 25"}
for name in birthdays:
print("Happy Birthday,", name + "! Your big day is", birthdays[name])
# Mini-project step 2: Ask for a name and check for their birthday.
person = input("Check if a birthday is coming up! Enter a friend's name: ")
if person in birthdays:
print("Yes!", person + "'s birthday is on", birthdays[person])
else:
print("Sorry, no birthday foundbut you can add it!")
# Sometimes things can go wrong with automation.
try:
value = int(input("Type a number to double: "))
print("Doubled:", value * 2)
except ValueError:
print("That was not a number. Please try again.")
# You can use functions to reuse your automation.
def greet(name):
print("Hello,", name, "! This greeting was automated just for you.")
greet("Taylor")
greet("Jordan")
# Challenge: Automate filling a simple form.
answers = []
questions = ["Name", "Favorite color", "Lucky number"]
for q in questions:
reply = input("Please enter your " + q + ": ")
answers.append(reply)
print("Form filled:", answers)
Recap: You Are Ready to Automate!#
You learned how to automate repetitive tasks with loops, lists, input, and built-in tools.
You built birthday reminders and filled forms the easy way.
Every task you automate is a little more free time for you.
Keep practicing and try automating something new today!
Thanks for Watching!#
Like, subscribe, and share if you enjoyed the lesson.
Tell us in the comments what you want to automate next!
Happy automating!
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



