Interactive Python for Beginners: Your First Script

Get Started with Python Interactive Coding Using Quarto Live

This tutorial guides you through setting up Python for interactive coding with Quarto Live. Learn how to write, edit, and run your first Python script directly in your web browser.

Tools
Author
Affiliation
Published

March 19, 2025

Keywords

interactive Python for beginners, first Python script, Python interactive coding

Introduction

Interactive coding in Python lets you experiment with code and see results immediately in your web browser. Using Quarto Live with the pyodide engine, you can write, edit, and run Python scripts interactively—without additional setup. This tutorial provides a clear, step-by-step guide to help you get started.



In this tutorial, you’ll learn how to:

  • Set up your Python interactive environment using Quarto Live.
  • Write your first Python script that prints a greeting and performs a simple calculation.
  • Modify the code and observe immediate output.

Detailed Walkthrough

Understanding the Code

Let’s break down a simple Python script:

  1. Print a Message:
    The print() function displays text in the console.
  2. Perform a Calculation:
    The script adds two numbers (10 and 5) and stores the result.
  3. Display the Result:
    The result is printed along with a descriptive message.

Example Walkthrough

# Print a welcome message
print("Hello, Interactive Python!")

# Perform a calculation: add 10 and 5
result = 10 + 5

# Display the result
print("10 + 5 =", result)

Your First Interactive Python Script

Try running the code block below. Then, modify it to experiment with different arithmetic operations or change the greeting message.

Source
```{pyodide}
print("Hello, Interactive Python!")
result = 10 + 5
print("10 + 5 =", result)
```
Note
  • Experiment by altering the calculation (e.g., try multiplication) or modifying the message to see how the output updates.
  • If you encounter any issues, refer to the troubleshooting tips below.

Troubleshooting Tips

  • Syntax Errors:
    Ensure your parentheses, quotation marks, and operators are correctly placed.
  • Variable Names:
    Verify that variable names are consistent and correctly spelled.
  • Execution Issues:
    If the code doesn’t run, refresh your browser or re-render the document.

Real-world Example: Calculating the Mean

Here’s a practical example that calculates the mean of a list of numbers using NumPy.

Source
```{pyodide}
import numpy as np

# Define a list of numbers
data = [10, 20, 30, 40, 50]

# Calculate the mean using NumPy
mean_value = np.mean(data)

print("The mean of the data is", mean_value)
```
Note

This example shows how interactive Python can be used for simple data analysis.

Further Reading

Conclusion

This tutorial provided a step-by-step guide to creating your first interactive Python script using Quarto Live. By experimenting with the examples and exercises, you’ll develop a solid foundation in interactive Python coding. Continue exploring the further reading resources to deepen your understanding and build more complex interactive projects.

Back to top

Reuse

Citation

BibTeX citation:
@online{kassambara2025,
  author = {Kassambara, Alboukadel},
  title = {Interactive {Python} for {Beginners:} {Your} {First}
    {Script}},
  date = {2025-03-19},
  url = {https://www.datanovia.com/learn/interactive/python/basics.html},
  langid = {en}
}
For attribution, please cite this work as:
Kassambara, Alboukadel. 2025. “Interactive Python for Beginners: Your First Script.” March 19, 2025. https://www.datanovia.com/learn/interactive/python/basics.html.