Concepts / Writing and Running Your First Python Program

Writing and Running Your First Python Program

The software development process has five phases: What (Analysis), Do It (Implementation), Test (Testing and Debugging), Use (Operation or Deployment), and Maintain (Refinement).

  • Programming

From Idea to Working Program

Writing software is more than typing instructions. It is a structured journey from an idea to a working program that solves a problem. In this course, you will repeatedly move through a simple pattern: understand what you want to build, write a small piece of Python, run it, check the result, and then decide what to add next.

The recommended approach is to build a simple version first, test it thoroughly, verify that it works, and then add features incrementally.

Starting small reduces risk. A simple version is easier to test, helps you discover whether your basic approach works, and gives you a stable foundation for later improvements. If the approach is wrong, you have invested less time before correcting it.

The Five Development Phases

The software development process has five phases. Each phase has a different purpose, and using them in order helps you plan work, find problems, and create software that can be used and refined.

planimplementverifyrefinenext improvementWhatAnalysisDo ItImplementationTestTesting and DebuggingUseOperation or DeploymentMaintainRefinement
What happens in the What, Do It, Test, Use, and Maintain phases, and how does the process cycle back as the program evolves?
PhasePurpose
WhatAnalysis: decide what the program should do
Do ItImplementation: write the code
TestTesting and Debugging: run the program with test data and check for errors
UseOperation or Deployment: use the program with real data to verify that it works
MaintainRefinement: improve the program based on what you learn

The five software development phases

For a small Python script, What might mean deciding the problem the script should solve. Do It means writing the script. Test means running it with test data and checking for errors. Use means applying it to real data to ensure it works. Maintain means refining the script based on what you learn.

The Do It-Test-Use Cycle

Although all five phases belong to the complete process, practical programming usually proceeds iteratively. You analyze and design a small part, implement it, test and debug it, use it to verify correctness, and then add a feature. The cycle repeats as the program grows.

runworkslearnimplementDo Itsimple versionTestfind and fix problemsUseverify with real useNext featureincremental addition
How does a programmer move from implementing a small feature to testing it, using it, and deciding what to build next?

Planning a Small Message Program

Apply the five phases to a simple Python program that displays a message.

What: Decide that the program should display a message.

Do It: Write a simple print statement.

Test: Run the statement and check whether the expected message appears.

Use: Use the working program when the message is needed.

Maintain: Refine the program if the message or its behavior needs to change.

The program is developed as a working small version before further features are added.

Where Your Python Runs

Python is a programming language: a formal set of instructions that a computer can understand and execute. In this course, you write Python code in your browser, and the code runs in the cloud on a server. The server's Python interpreter reads and executes the code, then sends the result back to your browser.

presentsend codeprovide codereturn resultCourse materialsPython codeBrowserlearner inputCloud serverexecution environmentPython interpreterreads and executesDisplayed resultbrowser output
How does Python code move from learner input to the execution environment and then produce output?
ModeHow code is organizedUseful for
REPLPython reads and runs one line at a time, displays the result, and waits for the next lineExperimenting and testing small ideas quickly
ScriptA saved file contains multiple lines of Python code and runs as a complete programWriting and running longer programs

Writing Versus Running

Writing code means entering a Python instruction or placing it in a script. Running code means sending that instruction to the Python environment so the interpreter can read and execute it. The two actions are connected, but they are not the same action.

sendproducePython instructionentered or savedPython interpreterreads and executesProgram resultdisplayed output
What is the difference between entering or saving a Python instruction and sending it to the Python environment for execution?

In the REPL, the distinction happens quickly: you enter one line, run it, see the result, and then enter another line. In a script, you can write several lines first and run the complete saved file. Both modes use the same Python language; they differ in how code is organized and executed.

Your First Python Statement

A Python statement is a complete instruction. The simplest statement in this lesson is a call to the print function. The function displays the text supplied to it.

python
Output
Hello, Python
executesprintfunction name(opening punctuationHello, Pythonargument)closing punctuationHello, Pythondisplayed result
Which parts of a simple Python instruction represent the function, the value or argument, the punctuation, and the resulting output?

Every function call follows the pattern function name, parentheses, and input inside the parentheses. In this statement, print is the function name. The parentheses show that the function is being called, and the text inside them is the argument given to the function. When the interpreter runs the statement, the text appears on the screen.

entersenddisplay resultLearnerenters statementBrowsersends codePython interpreterexecutes statementScreenshows output
What sequence of events occurs after a learner runs a Python statement, from entering the instruction to seeing its result?

Names and Values

After printing a fixed message, you can give values names. A variable is a name that holds a value. Assignment uses the equals sign to associate a value with a variable name so that you can use the name later.

name = "Alice" age = 25 print(name) print(age)

Output
Alice
25

When you use a variable name, Python retrieves the value associated with that name. This makes code readable and reusable because you can use a name instead of repeatedly typing the same value.

Mistakes Beginners Make

  • Treating writing code as the same as running code

    An instruction produces output only when the interpreter reads and executes it.

    Fix: After entering or saving the instruction, run it in the course environment.

  • Trying to build every feature before testing

    Problems may be discovered late, after more time and complexity have been added.

    Fix: Build a simple version, test it thoroughly, use it, and then add the next feature.

  • Confusing a function name with a function call

    Parentheses indicate that the function is being called and contain its input.

    Fix: Use the function name followed by parentheses with the argument inside.

  • Expecting a variable name to display its value without an instruction

    Assignment associates a value with a name; print is the statement described for displaying a value.

    Fix: Use print with the variable name when you want the value displayed.

Practice the Full Process

EASY

Plan a tiny Python program that displays a message. Describe what you would do in the What, Do It, Test, Use, and Maintain phases. Then write and run a print statement for the first version.

Hints
  • Start by identifying the message the program should display.
  • Use the print function with the message as its argument.
  • Run the statement and compare the displayed result with what you expected.
  • Think of one small refinement you could make after the first version works.

What do you think happens?

What output do you expect after running the following statement?

  • The text Hello, Python
  • The word print
  • No output because the statement only defines a function
Reveal answer

Answer: The text Hello, Python

print is a function call, and the text inside its parentheses is the argument that the function displays.

What to Remember

  1. The five software development phases are What, Do It, Test, Use, and Maintain.
  2. The recommended iterative approach builds a simple version, tests it, uses it to verify correctness, and then adds features.
  3. In this course, Python runs in a cloud-based interpreter through your browser, so no installation is needed.
  4. The REPL runs Python one line at a time, while a script is a saved file containing multiple lines of code.
  5. A print statement contains a function name, parentheses, and an argument; running it makes the argument appear as output.
  6. Writing code and running code are different: writing creates the instruction, while running sends it to the interpreter for execution.

Key Takeaways

  • Software development follows five phases: What, Do It, Test, Use, and Maintain.
  • The practical development cycle is iterative: implement a small version, test it, use it, and repeat with new features.
  • This course sends Python code from your browser to a cloud-based interpreter and displays the result back in the browser.
  • Python can run interactively in the REPL or as a complete script file.
  • A simple print statement demonstrates how a Python instruction is written, executed, and turned into output.