> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Your First Program

> Hands-on tutorial teaching how to write and run basic Python scripts using print, build a small dashboard, and diagnose common syntax and runtime errors.

Welcome back! This hands-on lesson walks you through writing and running simple Python scripts, using `print()` to display output, and diagnosing common syntax and runtime errors. Pause the video or step away from distractions when you need to concentrate — this is a practical exercise.

By the end you will:

* Create and run basic Python scripts.
* Use `print()` to display text and blank lines.
* Identify and fix common syntax and runtime errors.

***

## Prepare the editor (no install required)

Open a new browser tab and launch the KodeKloud Python Playground:

* [https://kodekloud.com/playgrounds/playground-python](https://kodekloud.com/playgrounds/playground-python)

The Playground provides a VS Code–style IDE in your browser. Typical layout:

* Explorer (left) — your project files.
* Editor (center) — write and edit code.
* Terminal/Console (bottom) — run scripts and view output.

Example terminal prompt you may see:

```bash theme={null}
root@host01 ~/code »
```

***

## 1) Your first script: hello.py

Create a new file named `hello.py` (the `.py` extension indicates a Python file). Add this content:

```python theme={null}
print("Hello, World!")
```

Run it from the editor (right-click → Run) or from the terminal:

```bash theme={null}
python hello.py
```

Expected output:

```bash theme={null}
root@host01 ~/code via 🐍 v3.12.3 * /bin/python /root/code/hello.py
Hello, World!

root@host01 ~/code via 🐍 v3.12.3 *>
```

How this works:

* `print` is a built-in function that displays text in the console.
* Parentheses `()` enclose the function arguments.
* Quotation marks `"` denote a string literal.
* The text inside the quotes is printed to the console.

Make it personal by changing the message:

```python theme={null}
print("Hello, I'm Alan.")
```

Then run:

```bash theme={null}
python hello.py
```

Tip: When using the terminal, press the Up arrow to cycle through previous commands.

***

## 2) Build a small dashboard: dash.py

Create `dash.py` and add a simple header and greeting:

dash.py:

```python theme={null}
print("================================")
print("DAILY DASHBOARD")
print("================================")
print()
print("Welcome back!")
```

Run it:

```bash theme={null}
python dash.py
```

Output:

```bash theme={null}
root@host01 ~/code via 🐍 v3.12.3 ➜  python dash.py
================================
DAILY DASHBOARD
================================

Welcome back!

root@host01 ~/code via 🐍 v3.12.3 ➜
```

Note: Using an empty `print()` produces a blank line and improves readability.

<Callout icon="lightbulb" color="#1CB2FE">
  Using `print()` without arguments prints a blank line. This is handy for spacing your output for readability.
</Callout>

Customize the greeting and add wellbeing and goals sections:

dash.py:

```python theme={null}
print("================================")
print("DAILY DASHBOARD")
print("================================")
print()
print("Welcome back, Ada!")
print()
print("WELLBEING")
print("Mood: Happy")
print("Energy: High")
print()
print("GOALS")
print("Learn Python basics")
```

Run again:

```bash theme={null}
python dash.py
```

Expected output:

```bash theme={null}
================================
DAILY DASHBOARD
================================

Welcome back, Ada!

WELLBEING
Mood: Happy
Energy: High

GOALS
Learn Python basics
```

***

## 3) Common errors: how to read and fix them

Errors are part of learning. Two common classes are syntax errors and runtime errors.

### Syntax error (example: missing quote)

If you omit a closing quote, the editor (VS Code) often highlights the issue and shows a problem in the Problems panel.

Faulty code:

```python theme={null}
print("=================================")
print("DAILY DASHBOARD")
print("=================================")
print()
print("Welcome back, Ada!")
print()
print("WELLBEING")
print("Mood: Happy")
print("Energy: High")
print()
print("GOALS")
print("Learn Python basics)
```

Running it produces:

```bash theme={null}
root@host01 ~/code via 🐍 v3.12.3 ✖ python dash.py
  File "/root/code/dash.py", line 12
    print("Learn Python basics)
                                 ^
SyntaxError: unterminated string literal (detected at line 12)
```

Fix: add the missing closing quote and rerun.

### Runtime error (example: wrong case)

Python is case-sensitive. If you accidentally capitalize `print` as `Print`, the interpreter will raise a runtime error:

Faulty code:

```python theme={null}
print("================================")
print("DAILY DASHBOARD")
print("================================")
print()
print("Welcome back, Ada!")
print()
print("WELLBEING")
print("Mood: Happy")
print("Energy: High")
print()
print("GOALS")
Print("Learn Python basics")
```

Run it:

```bash theme={null}
python dash.py
```

Traceback:

```bash theme={null}
Traceback (most recent call last):
  File "/root/code/dash.py", line 12, in <module>
    Print("Learn Python basics")
    ^^^^^
NameError: name 'Print' is not defined. Did you mean: 'print'?
```

Fix: use the correct lowercase `print`.

<Callout icon="warning" color="#FF6B6B">
  Python is case-sensitive: `print` is different from `Print`. Always use the correct case for functions, variables, and keywords.
</Callout>

***

## Quick reference: commands & tips

| Action | Command / Example |
| - | - |
| Run a script | `python hello.py` |
| Create a file | Use the Explorer or `touch hello.py` in terminal |
| Print a blank line | `print()` |
| Cycle command history in terminal | Up / Down arrow keys |
| Official Python docs | [https://docs.python.org/3/](https://docs.python.org/3/) |

***

## Recap

* You wrote and ran Python scripts using `print()` to display text.
* Use parentheses for function arguments and quotes for strings.
* `print()` with no arguments prints a blank line.
* Syntax errors (missing quotes, unmatched parentheses) are often flagged by the editor.
* Runtime errors (wrong case, undefined names) show up when running your program; read tracebacks to locate the problem.
* Practice using variables next to store and display data.

Before finishing, download your customized `dash.py` so you have a local copy. If your playground session ends, you can upload the file back into the Playground later.

Further reading:

* Python official docs: [https://docs.python.org/3/](https://docs.python.org/3/)
* KodeKloud Playgrounds: [https://kodekloud.com/playgrounds/playground-python](https://kodekloud.com/playgrounds/playground-python)

Good luck — complete the lab to practice and solidify what you've learned!

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/programming-fundamentals/module/b7e10a6f-82c0-4b55-a099-66ea1a6d06d4/lesson/6a90ece0-e24c-48be-a932-ee12653b6036" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.