Your First Program: Making the Computer Say Something Back
Okay so here's the thing. You've got Python installed. You've got an editor open. That was the boring part, and it's done.
Now we're going to make the computer say something back to you. Feels small. It's not small. This is the exact moment where coding stops being an idea in your head and starts being a real thing you did.
Open a new file
In your editor, start a brand new file. Save it right away, before you type anything, and name it something like hello.py. That .py at the end matters. It tells the computer and the editor "this is Python, treat it that way."
Save it somewhere you'll actually find again. I'd make a folder called something like python-class on your desktop or in your documents, and just keep everything from this course in there. Future you will say thanks.
Type this in
Not copy and paste. Type it. I mean that.
``python print("Hello, I'm making the computer talk.") ``
That's it. That's the whole program.
Here's why I'm making you type it instead of pasting it in: your fingers learn things your eyes skip right past. When you type it yourself, you notice the quotation marks, you notice the parentheses, you notice that print is lowercase. Paste it in and none of that sticks. Type it and it starts to feel normal in your hands. I'm firm on this one, so.
Run it
However your editor runs a file, whether that's a button that says "Run" or a little green triangle or a keyboard shortcut, use it now. Somewhere on your screen a line should show up that says:
`` Hello, I'm making the computer talk. ``
If that happened, congratulations, you just wrote and ran a computer program. Genuinely. That counts. Say it out loud if you want, I won't judge you, I did the same thing in my kitchen a few years back and it felt like I'd pulled off a heist.
When it doesn't work
It might not work the first time. That's normal, expected, and honestly kind of the point of this lesson.
Most likely problem: a missing quotation mark, a missing parenthesis, or a stray space somewhere you didn't mean to put one.
Let me tell you about the two hours of my life I will never get back. I was convinced my code was broken in some deep, complicated way. I checked the logic six times. I rewrote whole chunks of it. Two hours in, I found it. One extra space. One. In a spot that looked completely identical to every other spot around it. I sat there afterward and just quoted an entire comedy special out loud to my empty office, because I needed to feel like a person again and not a computer's punching bag.
I tell you that so when this happens to you, and it will, you don't think something's wrong with you. Something's wrong with a space. It happens to everybody who's ever typed code, including people who do this for a living. Read your line slow, character by character, and check the boring stuff first: quotes, parentheses, spaces.
Change what it says
Now go back in and change the words inside the quotation marks to whatever you want. Your name. A joke. An insult directed at your printer. Save the file again, run it again, watch it change.
Do that a few times. Break it on purpose, even. Delete one of the quotation marks and run it, see what the computer says when it's mad at you. Put the quote back, run it again, watch it get happy. This is the whole rhythm of coding, by the way: change something, run it, see what happens, adjust. You'll do that ten thousand more times in this class alone.
A quick word on "print"
You're going to use print constantly in this class, way past today. My son, who's 21 and very sure of himself about computers, once watched me debugging something and said "oh, you're using print statements like a caveman." He wasn't wrong. I still do it, all the time, because sticking a print statement into your code to see what's actually happening in there is faster than most of the fancy tools and it works. Don't let anybody make you feel behind for using the simple tool. The simple tool is often the right tool.
Before next time
Get comfortable running your file more than once with different messages in the quotes. If you've got a few extra minutes, try making it print two different lines, one right after the other. No pressure to get it perfect, just get your hands used to typing, saving, and running. That loop is ninety percent of this whole class.