Writing Your First Python Program¶
🐍 Meet Your Best Friend: The Python Interpreter¶
Before we dive deep into Python, let’s get one thing straight:
👉 Python interpreter is your friend — not your enemy.
When you write code, the Python interpreter is like a teacher who watches you work. If you make a mistake, it doesn’t yell at you — it tells you exactly where things went wrong.
💬 Example 1: A Small Typo¶
print("Hello world"Output:
SyntaxError: unexpected EOF while parsingPython is saying:
“Hey, you forgot a closing bracket at the end. Please fix it!”
That’s not anger — that’s guidance. ❤️
💬 Example 2: A Missing Variable¶
print(name)Output:
NameError: name 'name' is not definedPython gently reminds you:
“I don’t know what ‘name’ is yet. Did you forget to create it?”
💬 Example 3: Dividing by Zero (Oops!)¶
print(10 / 0)Output:
ZeroDivisionError: division by zeroPython:
“Bro... you can’t divide by zero. Let’s fix that before the universe collapses. 😅”
💡 The Key Idea¶
When you see an error:
Don’t panic ❌
Read it carefully ✅
It usually tells you exactly what’s wrong and where it happened.
Every “error” is actually a free Python lesson.
🧠 Pro Tip¶
If you learn to read Python’s error messages, you’ll debug faster than 90% of beginners. Errors are not punishment — they’re feedback.
🎯 In short:
The Python interpreter is not your enemy — it’s your most patient teacher.
First Code Blood: Python’s Origin Story as a Corporate Hitman
Hey, code virgins—imagine Python as the quiet guy in the office who one day snaps, grabs a keyboard, and turns the entire finance department into a ghost town. No “Hello World” bullshit here. That’s for amateurs who think programming is a tea party. We’re diving straight into building a profit-sucking machine that makes your boss question his life choices. By the end, you’ll have a script so slick, it’ll calculate quarterly gains faster than a Wall Street wolf snorts a line.
Ready? Let’s arm you with the basics—think of it as handing a toddler a chainsaw.
STEP 1: The Bare-Bones Profit Vampire¶
## This ain't no friendly calculator—it's a vampire draining corporate blood
sales = 25000 # Boss's monthly haul (sucker)
profit_margin = 0.28 # The "fair" cut (ha!)
fixed_costs = 7500 # Rent, coffee, that guy who does nothing
profit = sales * profit_margin - fixed_costs
print(f"🩸 Profit sucked dry: ${profit:,.0f}")
print("😈 Corporate soul harvested!")What spits out?
🩸 Profit sucked dry: $4,500
😈 Corporate soul harvested!Boom. You just turned numbers into cold hard cash—while Excel users are still fumbling for the SUM button like it’s a blind date.
The Autopsy: How You Just Assassinated Manual Math¶
| Code Organ | What It Devoured | Corporate Casualty |
|---|---|---|
sales = 25000 | Swallowed revenue | One accountant fired |
profit_margin = 0.28 | Multiplied the lies | Two VLOOKUPs deleted |
fixed_costs = 7500 | Subtracted the excuses | Entire “finance meeting” |
print(f"...") | Spat out the corpse | Boss’s ego deflated |
Mind twist: This “simple” code is the same logic hedge funds use to skim billions—except theirs has more zeros and fewer ethics.
STEP 2: Make It a Stalker—Interactive Edition¶
## Now the vampire asks for victims
company = input("🏴☠️ Name the company to bleed: ")
sales_input = input("🩸 Monthly revenue to drain: $")
sales = float(sales_input) # Convert string blood to numbers
profit = sales * 0.28 - 7500
print(f"\n💀 BLOOD REPORT FOR {company.upper()}")
print(f" Drained revenue: ${sales:,.0f}")
print(f" Profit harvested: ${profit:,.0f}")
print(f" Status: {'☠️ BANKRUPT' if profit < 0 else '🧛♂️ VAMPIRE FED'}")Test run: Input “Enron” and “1000000”. Watch the vampire feast. (Pro tip: Negative profit? Company implodes. Hilarious.)
STEP 3: The Quarterly Bloodbath—Scale the Slaughter¶
## Upgrade: Drain 3 months at once!
months = ['Jan', 'Feb', 'Mar']
revenues = [25000, 28000, 32000] # Growing victims
total_revenue = sum(revenues)
avg_revenue = total_revenue / len(months)
total_profit = sum(r * 0.28 - 7500 for r in revenues)
print("🧛♂️ QUARTERLY BLOOD ORGY REPORT")
print(f" Victims drained: ${total_revenue:,.0f}")
print(f" Average haul: ${avg_revenue:,.0f}")
print(f" Profit feast: ${total_profit:,.0f}")
print(f" Horror level: {'🔪 SERIAL KILLER' if total_profit > 10000 else '🩸 FIRST-TIMER'}")YOUR BLOOD PACT: Forge Your Profit Vampire¶
## CUSTOMIZE: Make it YOUR monster
company_name = "???" # Your vampire's lair
monthly_revenue = ??? # Blood supply
profit_margin = ??? # Fang sharpness (0.35 = 35%)
fixed_costs = ??? # Victim resistance
net_profit = monthly_revenue * profit_margin - fixed_costs
print(f"""
🧛♂️ VAMPIRE SPAWN: {company_name.upper()}
═══════════════════════════════
🩸 Monthly blood: ${monthly_revenue:,.0f}
🦷 Fang strength: {profit_margin*100:.0f}%
🏰 Lair costs: ${fixed_costs:,.0f}
💀 NET HARVEST: ${net_profit:,.0f}
🎯 Fate: {'🩸 BLOODLUST' if net_profit > 10000 else '🦇 STARVING BAT'}
""")Spawn ideas:
Lair: “VampCoffee” | Blood: 18000 | Fang: 0.35 | Resistance: 6000
Lair: “BloodTech” | Blood: 75000 | Fang: 0.22 | Resistance: 15000
Run 3 spawns → Screenshot your most bloodthirsty vampire → Send to group chat
SKILLS YOU’VE SACRIFICED FOR¶
| Vampire Power | Blood Type Learned | Corporate Victims |
|---|---|---|
| Variables | Data draining | 5 accountants |
| Math ops | Profit extraction | 12 Excel ghosts |
input() | Victim selection | 3 finance departments |
| f-strings | Horror formatting | Entire boardroom |
VAMPIRE PRO TIPS (Bite Harder)¶
## Format blood like a pro vampire
print(f"${12345:,.0f}") # $12,345
## Multi-drain calculations
revenue, profit = 25000, 4500
print(f"Blood: ${revenue:,.0f} | Harvest: ${profit:,.0f}")
## Notes = Immortal lore
sales = 25000 # Monthly blood in dollarsTHE BLOOD OATH CEREMONY¶
print("🩸" * 20)
print("💀 VAMPIRE AWAKENED!")
print("🩸 You can now:")
print(" • Drain profits")
print(" • Build blood tools")
print(" • Terrify professors")
print(" • Collect job offers")
print("🩸" * 20)Next: Business Use Cases (Python’s greatest corporate massacres revealed!)
The exercises below are interactive. Edit the code and re-run each `pyodide-cell` to see instant results in the browser.Exercises¶
Exercise 1¶
Write a function count_vowels(s) that returns the number of vowels in the input string s. Test it on a sample word.
Exercise 2¶
Create a function compute_profit(sales, profit_margin=0.28, fixed_costs=7500) that returns the net profit. Call it with a sample value and print the result.
Exercise 3¶
Given a list of monthly revenues, write quarter_summary(revenues) that returns total and average revenue. Test with a sample list.