Key Takeaways
Start learning Python with one small program: install Python 3, run the code, predict its output, and then check it. Use AI to explain an unfamiliar part and offer hints. Below, you will build a study-time counter that introduces variables, a list, a loop, and a condition.
This guide is for you if you have not started programming yet. Your first goal is to explain each step of the code and independently predict what one change will do.
What do you need for your first program?
You need Python 3 and somewhere to write and run code. Choose installation instructions for your operating system from Python's official getting-started guide (source 1). The example below needs no additional packages.
You can start with IDLE, Python's learning environment. If IDLE is missing from your installation, follow your Python distributor's instructions for adding it: IDLE is an optional component. Official IDLE documentation (source 2).
- Open IDLE and choose File → New File.
- Enter the code below in the new window and save the file as
study.py. - In the code window, choose Run → Run Module. You will see the output in the Shell window.
Do not include >>> markers in your source code. They are interactive prompt markers, not part of the program. How to read Python's examples (source 3).
Write a study-time counter
Suppose you studied three times: for 20, 15, and 25 minutes. Your goal is 60 minutes in total. The program should add up the time and tell you whether you reached the goal.
Before running it, write down two predictions: the total number of minutes and the message that will appear.
minutes = [20, 15, 25]
goal = 60
total = 0
for session in minutes:
total = total + session
print("Total minutes:", total)
if total >= goal:
print("Goal reached")
else:
print("Minutes remaining:", goal - total)
With these inputs, the output is:
Total minutes: 60
Goal reached
The first line shows the total minutes; the second tells you that you reached the goal. The English labels are text the program prints; changing them does not change the calculation.
Use zero or positive integers for both the minutes and the goal in this example. The program does not validate its data or reject negative durations. It is a small learning example.
Understand what each part does
| Code | What it does in this program |
|---|---|
minutes = [20, 15, 25] |
Stores a list of study-session durations |
goal = 60 |
Stores the desired total minutes |
total = 0 |
Starts the running total at zero |
for session in minutes: |
Takes each number from the list in order |
total = total + session |
Adds the current duration to the running total |
if total >= goal: |
Checks whether the total is greater than or equal to the goal |
else: |
Takes the other path when the goal has not been reached |
The indented lines beneath for, if, and else belong to their respective blocks. Keep the four-space indentation used in the example. Find more loop and condition examples in Python's official tutorial (source 4).
Now look at the code and explain aloud: why does total become 20, then 35, and finally 60? Once you understand that, you have a foundation for the next step.
How can you use AI while learning?
Ask AI to explain one unfamiliar part. For example, if you do not understand for, you do not need the whole program rewritten. Give it your code, your prediction, and a specific question.
One option is Gemini's Guided Learning mode. Google's current instructions say to sign in on a computer, open Add Files in the text box, then More tools → Guided Learning, and submit a question. If you cannot find the feature in the mobile app, try the web version. Google's official instructions (source 5).
You can send this request along with your code:
I am learning Python from scratch. I want to understand the for loop in the attached code.
Do not give me a complete solution. First ask what value total will have
after the first iteration, and wait for my answer.
Then give me one short hint and let me try again.
Do not introduce new packages or additional functions yet.
You can try the same approach in a regular AI chat if a dedicated mode is unavailable. The request specifies your preferred response format, but AI may still provide too much code. If that happens, ask it to return to just one question.
Check AI's explanation by running the code. A convincing answer is not proof of a correct calculation. If the assistant suggests installing an unfamiliar package or running another command, first understand why you need it; this example requires no additional package.
Change the inputs and check both paths
For each attempt, change only minutes or goal, save the file, and run it again. Leave the rest of the code unchanged.
| Minutes list | Goal | Expected total | Expected message |
|---|---|---|---|
[20, 15, 25] |
60 |
60 |
Goal reached |
[10, 15] |
60 |
25 |
Minutes remaining: 35 |
[] |
60 |
0 |
Minutes remaining: 60 |
[40, 30] |
60 |
70 |
Goal reached |
These checks cover an exactly reached goal, insufficient time, an empty list, and exceeding the goal. Passing them does not establish the absence of every possible bug.
Separately, try the original list with the goal set to 90. Before running it, predict the number of remaining minutes. Then compare the output with your answer.
Look for one cause when something goes wrong
Before replacing the entire file with AI-generated code, read the last line of the error and look at the location it points to.
| Change | Error you will get | What to check |
|---|---|---|
Remove the colon at the end of for session in minutes: |
SyntaxError |
The : at the end of the for line |
| Remove the indentation from the loop's only body line | IndentationError |
The four spaces inside the block |
Write the goal as goal = "60" |
TypeError |
You are comparing text with a number; write the goal without quotes |
You can show AI the error, a few relevant lines, and what you expected. Ask it to explain the cause and suggest only the necessary change. Do not paste passwords, keys, or personal data into the chat.
Where should you go next?
Make your next exercise an extension of this counter: add another study session to the list and calculate the new total beforehand. Then learn about functions and try moving the calculation into a separate function.
Move on when you can explain the current code in your own words and predict its output for different inputs. If you later use an AI coding assistant, the guide to your first Codex task can help you define the scope of a change and the conditions for checking it.
A useful sign that you have completed this first stage is a working study.py file, check results that match your predictions, and the ability to explain why the if or else branch ran.
Full source addresses
https://www.python.org/about/gettingstarted/https://docs.python.org/3/library/idle.htmlhttps://docs.python.org/3/tutorial/introduction.htmlhttps://docs.python.org/3/tutorial/controlflow.htmlhttps://support.google.com/gemini/answer/16448384?hl=en
Updated: October 28, 2026



