🐍 Python Basics — 5 Interactive Modules
Each module runs separately via Pyodide. Output appears right below the code. Colored console output: 🟢 stdout / 🔴 stderr / 🟣 status
Module 1 — Hello & Print
Your first Python program — using
print() and input().# Module 1 — Hello & print
name = input("What's your name? ")
print(f"Hello, {name}! Welcome to Python basics.")
— output here —
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)
— output here —
Module 3 — Control Flow
Using
if/else, 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
— output here —
Module 4 — Functions & Modules
Defining functions and using Python's standard library.
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}")
— output here —
Module 5 — Lists & Comprehensions
Creating lists, 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])
— output here —
No comments:
Post a Comment