This is a computer class. But it isn't a hardware class. It's a software class. We'll write programs. Hundreds. Our language is Python. (Do not fear. It's named for the British comedy troupe, not the snake.)
Here's a little program. It draws a star.
import euclid
from colors import *
euclid.createPage(tracer = 0)
logos = euclid.Pen(color = RED, delay = 12)
w, h = euclid.getScreenSize()
center = (w//2 - 100, h//2)
logos.up()
logos.goto(*center) # goto expects two values; the star unpacks the center tuple
logos.down()
logos.beginRegion(YELLOW) # make the fill color YELLOW
while True:
logos.forward(200)
logos.turn(170)
if logos.distanceTo(*center) < 1:
break
logos.endRegion()
euclid.finish()
euclid.wait()
Mystified? I promise that if you do what I ask, you'll be able to write code like this within a few months.
You'll have grades of four sorts: Programs/Functions, Quiz, Project, Final. Programs/Functions will count for 70% of your quarter grade. Quizzes will count for 15%. Projects will count for 15%. The Final is 20% of your semester grade. We'll have a quiz at the end of each chapter.
We'll do five chapters in semester one and five in semester two. In each chapter, I'll teach you some new bit of Python. I'll also describe the functions I wish you to write. (Functions are for us the basic way in which we'll organize our code - all code will be a function or a collection of functions. More on this later.) If you do as I ask in the function descriptions, I can test your functions. I can test them with inputs of my choice and then tell you if their outputs are correct. This is called a unit test. Every set of functions descriptions is followed by a unit test, hand-crafted by Dr. M. Copy the unit test, paste it under your functions and run it. Once you do, you'll find a detailed report, and a final score, in a text file. I'll take the final score from the unit test and transfer it to my gradebook. (Expect detailed instructions about how to get and use the unit tests later.)
You'll also be asked to do a number of projects. (Here they are if you're curious.) Here you'll have more freedom. I provide only a description of the tasks your code should carry out; I don't tell you how to break your code up into functions. Of course it will consist of functions. We're function writers. But what they will be and how they will be organized - that's for you to decide.
When an assignment is due, you'll fill out a Google form and there provide the link to your code. (We'll use replit.com, and there each project has its own unique URL.)
At the end of each chapter, you'll take a quiz. They're already here on the class site. The quizzes will be paper and pencil.
The final will also be paper and pencil, and it too is already published (though I might supplement it a bit).
I’ve written a book. You're there right now.
I'll keep the schedule on Canvas, and I'll occasionally use Canvas to send announcements to the class.
You'll write your code at codehs.com. A wonderful feature of CodeHS - indeed the best feature, I think - is that every replit project has its own URL. When time comes to submit, you'll paste that URL into a Google Form. I can then both see your code and run it.
Code is very easy to steal. A Python program is a text file, and so you can simply copy and paste any bit of code you want. Moreover, a simple Google search will lead you to mountains of code. But yet I say, "Do not steal code!" You will of course study code written by others. But all of your code must be written by you. Why? Only if you've written the code yourself will you know how it works; and only if you know how it works will you be able to write correct code of your own. I also say that you should not give code away. You might think you've done a friend a favor, but actually you've hurt them. They need to learn to write their own code.
How will I know that you've written the code you submit? No doubt in some cases I'll be unable to detect stolen code. But stolen code often has a certain odor to it. It's more sophisticated than the code that the typical student is able to write, or it solves a problem similar to but distinct from the problem given.
If I suspect you've stolen code or accepted code that isn't your own, I'll call you up and ask you to explain your code in plain English. If you can explain it, I'll assume that the code is yours. If you can't, I'll conclude that you've cheated. Please don't be offended if I call you up and ask you to explain your code. If my suspicions are unfounded, I'll apologize profusely.
No doubt you're familiar with the apparent revolution in AI that began in 2022 with the public release of ChatGPT.
AI excels at some tasks. Code is one. I'm sure you'll feel a temptation to let AI write code for you. Resist the temptation. You're a beginner. You need to learn how to code, and if you let AI do your work for you, you won't learn. I do understand that the pros often use AI. My son, a software engineer, says that it significantly speeds up his work. But you're not a pro. Not yet.
Moreover, you take a risk if you let AI write code for you. The AI is often right. But of course it's sometimes wrong, and if you haven't learned to write code yourself, you won't know when it's wrong. This is why it's (mostly) safe for the pros to use AI but not safe for you. The pros can check the output of the AI and verify that it's correct when it is, and fix it when it's not. You're not at a point yet where you can do that.
A final point. If you let AI write your code for you, you'll rob yourself of the thrill you'll experience when you finally, after much time and frustration, solve that hard problem. Young coders who relies too much on AI impoverish themselves.
These should never be out in the classroom. Put them away before you come in. Keep them away until you're out the door.
We need a tool to write code, debug code (which means to fix the mistakes) and run code. Such a tool is called an "Integrated Development Environment" or "IDE" for short. We have Chromebooks, and no Chrome IDE exists for Python. Fortunately a few good in-browser IDE's exist. We'll use codehs.com. You'll need to sign up if you haven't already. Use your school Google account.
Once you've created an account and signed in, you'll create a new Python program. (It's easy. Just go to your Sandbox and then follow the on-screen prompts.) You'll then find yourself in CodeHS's Python IDE. On the left is all files for that repl, in the middle is the code editor and on the right is a console. I'll teach you about all that in the first few days.
The core concept of the class is the concept of a function. In Chapter 0, I explain why that is so.
Before we begin to write functions, we must know a little Python. We must in particular know to how to evaluate an expression, and how to assign a value to a variable and later retrieve that value.
Now that we understand expression value and variable assignment, we can write out first functions. In this course we are always function writers, and the solutions to our problems will be either one function or the composition of many.
Here we begin our study of the core logical tools provided by Python. In iteration (of the definite variety), we make a block of code execute a given number of times; and as we do, the value of a variable (or variables) evolves towards its final state.
We can make a block of code to execute repeatedly; that's iteration. In selection, we choose which (if any) of a set of blocks of code will execute. This is the second of our logical tools.
In Chapter 5 we turn from logic to data. The first of of the data types that we'll study in depth is the string. Files are simply strings stored externally.
Chapter 6 is the second of our data chapters. Python's most versatile data type is the list. Here we must grapple with the concept of mutation. Lists are mutable. Strings are not.
The last of the data types that we'll study are dictionaries and sets. Both are intrinsically unordered. With lists, indices are integers; but with dictionaries, indices (called now "keys") are objects of our choice. So a dictionary consists of a set of unordered key/value pairs.
In Chapter 8 we turn back to logic. In recursion, we find that if done properly a function can call itself. How do we escape the infinite loop this seems to create? We hit the base case!
A higher-order function is a function that either takes a function as input, returns a function as output, or both. Functions are thus a kind of logic/data hybrid - they do things (that's logic), but they are also things that can be used or modified by other functions (that's data).
With classes, we begin our study of the so-called "Object-Oriented Paradigm". We will learn here how to create new data types, and to specify the rules that govern them. This will culminate in the fraction and complex number projects. There you'll write code that teaches Python how to create and manipulate fractions and complex numbers.