🎉 Welcome to PyVerse! Start Learning Today

Python Syntax and How to Run Python Programs

Welcome to PyVerse! Python is a friendly programming language that lets you tell the computer what to do using simple, readable instructions. Think of Python syntax as the grammar and punctuation of a new language. Once you learn the basics, you can start creating cool programs fast.

How to Run Python Programs

Option A: Run in your web browser (easiest to start)

  1. Open any online Python editor (many free ones exist — your teacher may share one).
  2. Type this code: print("Hello, PyVerse!")
  3. Click Run. You should see: Hello, PyVerse!

Option B: Run on your computer with IDLE (comes with Python)

  1. Install Python 3 from python.org (ask an adult if needed).
  2. Open "IDLE (Python 3)".
  3. Click File > New File.
  4. Type: print("Hello, PyVerse!")
  5. Save as hello.py.
  6. Click Run > Run Module (or press F5). The output window will show: Hello, PyVerse!

Option C: Run from the terminal/command prompt

  1. Open a text editor, type: print("Hello, PyVerse!")
  2. Save as hello.py in a folder you know.
  3. Open Terminal (macOS/Linux) or Command Prompt (Windows).
  4. Go to the folder (use cd).
  5. Type: python hello.py
  6. If that doesn't work on macOS/Linux, try: python3 hello.py

Python Syntax Basics (What the rules look like)

1) Printing text

print("Hello, world")

Use parentheses and quotes around text.

2) Comments (notes that Python ignores)

# This is a comment that explains the code print(2 + 3) # This prints 5

3) Variables (names that store data)

name = "Ava" age = 14 print("My name is", name) print("I am", age, "years old")

4) Numbers and math

a = 7 b = 3 print(a + b) # 10 print(a * b) # 21 print(a ** b) # 343 (a to the power of b)

5) Strings (text) and combining them

first = "Py" second = "Verse" message = first + second print(message) # PyVerse

6) Indentation matters (spaces at the start of a line)

score = 85 if score >= 80: print("Great job!") # This line is indented print("Done") # This line is not indented

Use the same indentation inside a code block (usually 4 spaces).

7) Case-sensitive

print is not the same as Print or PRINT. Use exact names.

Common Syntax Mistakes (and quick fixes)

  • Missing quotes - Wrong: print("Hello) | Right: print("Hello")
  • Forgetting parentheses in print - Wrong: print "Hi" | Right: print("Hi")
  • Bad indentation - Make sure your if/else blocks are properly indented
  • Mismatched quotes - Wrong: print('Hello") | Right: print("Hello") or print('Hello')

Simple, Working Examples

1) Greeting

print("Welcome to PyVerse!") print("Let's learn Python.")

2) Mini profile

name = "Zara" hobby = "basketball" print("Hi, I'm", name) print("I like", hobby)

3) Tiny calculator

x = 12 y = 4 print("x + y =", x + y) print("x / y =", x / y)

4) If statement with indentation

temperature = 30 if temperature > 25: print("It's warm today!") print("Remember to drink water.")

Mini Activity: Your Turn

Goal: Make a small program and run it (online editor or IDLE).

  1. Create a new Python file (hello_you.py).
  2. Type these lines, then change the values to your own:
name = "YourName" favorite_number = 7 print("Hello,", name + "!") print("Your favorite number is", favorite_number)
  1. Add one more line that prints a fun fact about yourself using a comment and a print:
# Fun fact: I love science! print("Fun fact: I love science!")
  1. Run your program and check the output.

Bonus (optional): Try an if statement

age = 14 if age >= 13: print("You can make cool teen projects with Python!") print("Keep coding!")

Summary

  • Python syntax is the set of rules for writing code: use print(...), quotes for text, variables to store data, and consistent indentation for blocks.
  • You can run Python in a browser, in IDLE, or from the terminal.
  • Start simple: print messages, use variables, and try small steps.
  • If you see an error, read it, check quotes and indentation, and try again. Every coder fixes mistakes—that's how you learn.

Loading quizzes...