Sunday, 2 November 2025

#20 Python Revisit ( + In Browser Python Run)

Python basics — 5 modules (interactive)

Syntax highlighting via Prism.js. In-browser execution via Pyodide. Colored console output: ๐ŸŸข stdout / ๐Ÿ”ด stderr / ๐ŸŸฃ status.

Interactive runner

Paste examples into the editor (or use Copy & Use from any module) and click Run. Output appears below.
Editor
Pyodide status: loading...
Quick snippets
Console output
— ready —

Module 1 — Hello & print

The first program: printing to console, comments, and basic I/O.
# Module 1 — Hello & print
name = input("What's your name? ")
print(f"Hello, {name}! Welcome to Python basics.")

Module 2 — Variables & Types

Numbers, strings, booleans, and type checking.
x = 42
y = 3.14
name = "Ada"
is_ready = True

print(x, type(x))
print(y, type(y))
print(name.upper(), type(name))
print("Is ready?", is_ready)

Module 3 — Control Flow

if/else, for loops, while loops, and range.
n = 5
for i in range(1, n+1):
    if i % 2 == 0:
        print(i, "is even")
    else:
        print(i, "is odd")

count = 3
while count > 0:
    print("Counting down:", count)
    count -= 1

Module 4 — Functions & Modules

Defining functions, parameters, return values, and importing a module.
import math

def circle_area(radius):
    return math.pi * radius ** 2

r = 2.5
print(f"Area of circle with radius {r} is {circle_area(r):.3f}")

Module 5 — Lists & Comprehensions

Creating lists, indexing, slicing, and list comprehensions.
numbers = [1, 2, 3, 4, 5]
squares = [n**2 for n in numbers]
evens = [n for n in numbers if n % 2 == 0]
print("numbers:", numbers)
print("squares:", squares)
print("evens:", evens)
print("first two:", numbers[:2])

No comments:

Post a Comment

#20b Python (run+edit in browser ^ all in one)

๐Ÿ Python Basics — 5 Interactive Modules Edit code live with syntax highlighting and click ▶ Run . Each module runs separately ...