> Source URL: /resources/running-code.resource
# Running Code

## What It Is

Running code means telling your computer to execute the instructions you've written. When you run a Python file, the computer reads your code line by line and performs each action.

## Why We Use It

Writing code is only half the job — you need to run it to see what it does! Running your code lets you:

- See your program's output immediately
- Test if your code works correctly
- Find and fix errors (a normal part of coding!)

It's like drawing up a play in sports: the diagram is important, but you have to run it on the field to see if it works.

---

## How to Run Python Code in Cursor

### Method 1: Using the Terminal (Recommended)

1. **Save your file** using **File > Save** (or `Cmd + S` on Mac, `Ctrl + S` on Windows/Chromebook) — always save before running!
2. **Open the terminal** using **View > Terminal** (or `Cmd + ~` on Mac, `Ctrl + ~` on Windows/Chromebook)
3. **Navigate to your file's folder** (if needed):
   ```
   cd /path/to/your/folder
   ```
4. **Run your Python file:**
   ```
   python achievement.py
   ```
5. **See the output** appear in the terminal

### Method 2: Using the Run Button

1. Save your file
2. Look for a "Run" or "Play" button (▶) in the top-right of the editor
3. Click it to run your code
4. Output appears in the terminal below

---

## Understanding Terminal Output

When you run your code, you'll see one of two things:

### Successful Output

```
$ python achievement.py
Wilt Chamberlain scored 100 points in a single game!
```

Your code ran and printed the message. Success!

### Error Messages

```
$ python achievement.py
  File "achievement.py", line 1
    print("Hello
          ^
SyntaxError: unterminated string literal
```

**Don't panic!** Errors are normal and helpful. They tell you:

- **Which file** has the problem (`achievement.py`)
- **Which line** to check (`line 1`)
- **What went wrong** (`unterminated string literal` — you forgot the closing quote)

---

## The Run-Check-Fix Cycle

Coding is an iterative process. You'll repeat this cycle many times:

```
  ┌──────────┐
  │  Write   │
  │   Code   │
  └────┬─────┘
       │
       ▼
  ┌──────────┐
  │   Run    │
  │   Code   │
  └────┬─────┘
       │
       ▼
  ┌──────────┐     Error?     ┌──────────┐
  │  Check   │ ─────────────► │   Fix    │
  │  Output  │                │   Code   │
  └────┬─────┘                └────┬─────┘
       │                           │
       │ Works!                    │
       ▼                           │
  ┌──────────┐                     │
  │   Done   │ ◄───────────────────┘
  └──────────┘
```

Every programmer, even professionals with decades of experience, goes through this cycle constantly.

---

## Common Pitfalls

| Problem                     | Solution                                                        |
| --------------------------- | --------------------------------------------------------------- |
| "No such file or directory" | Make sure you're in the right folder, or use the full file path |
| Nothing happens when I run  | Check that you saved the file, and that it has `.py` extension  |
| Old output still showing    | Scroll down in the terminal — new output appears at the bottom  |
| "python: command not found" | Try `python3` instead of `python`, or reinstall Python          |

---

## Quick Reference

```python
# Save your file first, then in terminal:
python achievement.py

# If that doesn't work, try:
python3 achievement.py

# To clear the terminal (start fresh):
# Mac: Cmd + K
# Windows/Chromebook: Type 'cls' and press Enter
```





---

## Backlinks

The following sources link to this document:

- [Running Code](/resources/index.resources.llm.md)
