How-to

Complete Python Foundation Training: Write Your First Useful Python Program

NerdIT · 4 Dec 2026 · 7 min read

Complete Python Foundation Training: Write Your First Useful Python Program

Learning to write a useful program is easier when you build it one part at a time. In this guide, you will make a small command-line task tracker: it asks for a task, checks the input, and prints a simple confirmation. The steps draw on topics in Complete Python Foundation Training, including input and output, types and values, conditions, loops, functions, and debugging.

You do not need to know Python already. You will need Python installed and a place to write and run a .py file. If you are still setting up, NerdIT’s Python training course includes an installation and environment setup lesson.

What you will build

The program will ask you to enter a task. If you submit a blank answer, it will ask again. When you enter a task, it will display a confirmation. This small workflow gives you practice with user input, strings, a condition, a loop, and a function.

A three-step flow from entering a task to handling blank input and displaying a response. Build the task entry flow one part at a time.

The Task entry flow has three parts: Ask for a task, Handle a blank answer, and Display the response.

It will not save tasks after the program closes. File handling and data storage are useful next topics once this basic flow makes sense.

Step 1: Create a Python file

Open your editor and create a file named task_tracker.py. A clear filename helps you recognise what the program is for. Make sure the file ends in .py so your editor treats it as Python code.

Python runs instructions in order, from top to bottom. You will add and run a little code at each stage, which makes it easier to spot where a problem begins.

Step 2: Ask for a task

Add this line to the file:

task = input("What task do you need to do? ")

The input() function displays a prompt and waits for a person to type a response. Python returns that response as text. The assignment stores the text in a variable named task, so the program can use it in a later instruction.

Run the file. At the prompt, type a task and press Enter. The program receives your answer, but it does not display it yet. That is expected: asking for input and showing output are separate actions.

Step 3: Display the response

Add a second line below the first:

print("Added task: " + task)

The print() function writes text to the screen. The plus sign joins the message with the value stored in task. Run the program again and check that the task you entered appears in the output.

The prompt text is a string, and the answer stored in task is also a string. Joining them works because both values are text. Python has other kinds of values too, such as numbers and Boolean values, each suited to different operations.

Step 4: Handle a blank answer

A person may press Enter without typing anything. Add a condition so the program can detect that case:

if task == "":
    print("Please enter a task.")
else:
    print("Added task: " + task)

The expression task == "" checks whether the answer is an empty string. The double equals sign compares values. The single equals sign in the assignment stores a value in a variable.

Python uses indentation to show which instructions belong to the if and else branches. Keep the print() lines indented underneath their branch. Try the program with a blank answer, then try it again with a task. Each path should show a different message.

Step 5: Ask again until the input is useful

The condition handles a blank answer once, but it does not ask again. Use a while loop to repeat the prompt until the answer is not blank:

task = ""

while task == "":
    task = input("What task do you need to do? ")
    if task == "":
        print("Please enter a task.")

print("Added task: " + task)

The loop checks its condition before each pass. While task is an empty string, the indented instructions run again. When you enter some text, the condition becomes false, the loop ends, and Python moves to the final print().

A comparison of the program response to a blank answer and to some entered text. The loop repeats only while the answer is blank.

Blank or useful input decides the path: a Blank answer means Ask again, and Some text means Loop ends.

Setting task to an empty string before the loop gives the condition a value to check. Without that assignment, Python would not know what task means at the point where it first checks the condition.

This pattern is handy whenever a program should keep asking until it receives usable input. Test it by pressing Enter at the prompt, then entering a task when it asks again.

Step 6: Put the workflow in a function

A function gives a group of instructions a name. Wrap the current workflow in a function so you can call it as one unit:

def add_task():
    task = ""

    while task == "":
        task = input("What task do you need to do? ")
        if task == "":
            print("Please enter a task.")

    print(f"Added task: {task}")

add_task()

The def line defines the function. The indented body contains its instructions. The final line calls the function, which tells Python to run that body.

Keep the function call at the left edge of the file. It is outside the function body. If you indent it by mistake, Python will treat it as part of the function instead.

Functions help make code easier to organise and reuse. As your program grows, you can give each function one clear job, such as asking for input, displaying a menu, or saving information.

Step 7: Make the confirmation clearer

An f-string starts with the letter f before the opening quote. Put a variable name inside braces to insert its value into the text. This approach is useful when a message includes several values because you can see the sentence in one place.

The function now uses print(f"Added task: {task}") to show the confirmation. Run the program and confirm that the output still includes the task you entered.

Step 8: Read an error carefully

A small typo can stop a program from running. If Python reports an error, read the final part of the message first. It often names the kind of problem and points to a line. Then inspect that line and the one above it for a missing quote, colon, bracket, or indentation.

For example, the line after while task == "": must be indented because it belongs to the loop. The line after if task == "": needs another indentation level because it belongs to the condition. Consistent spacing makes the program structure visible.

Change one thing at a time, run the file again, and see whether the error changes. This is a practical debugging habit: use the message as a clue and narrow down the cause instead of rewriting the whole program.

Step 9: Check the program with different inputs

Try these cases and confirm the program responds sensibly:

The program accepts any non-empty text as a task. It does not check whether the task is already on a list or store it for later. Those behaviours need additional data structures and file handling.

A useful next improvement is to collect tasks in a list. You could then add a loop that displays each item. A further step is to write the list to a file and read it when the program starts. The course covers lists and dictionaries, loops, functions, and file handling, which provide the building blocks for these changes.

Next steps

Try modifying the program so it asks whether the person wants to add another task. Use a condition to respond to the answer, then explore a loop that repeats the task entry workflow. Keep the code readable by moving each job into a function as the program grows.

For a structured path through Python syntax, data types, operators, control flow, functions, debugging, and file handling, visit Complete Python Foundation Training. You can also explore NerdIT’s free online courses to continue learning. Courses are free, and verified certificates are optional and paid.

Start learning — free

Complete Python Foundation TrainingIntermediate · Free to learn

Browse all free courses