Go to the latest lesson. See all classes.

Classroom and Self-Directed Learning Resources

First Day, 2024-03-12

Welcome to Computer Science

Join Your Class in Google Classroom

Computing in the News

Women in computing

MakeCode for micro:bit

Self-Directed Learning

2024-03-14

micro:bit game

micro:bit game

Self-Directed Learning

2024-03-19

Computing in the News: Grace Hopper

Questions

  • When did she live?
  • Where did she get her math and physics degrees?
  • Where did the term “debugging” come from?
  • What programming language did she help develop?
  • What computers did she work on at Harvard?
  • What did she say is her greatest accomplishment?

Programming the micro:bit in Python

micro:bit Python editor

Explore examples in the Ideas tab.

Self-Directed Learning

2024-03-21

Programming the micro:bit in Python

micro:bit Python editor

Tilting Dot Program

from microbit import *

x = 2
y = 2

while True:
    ax = accelerometer.get_x()
    if ax > 200 and x < 4:
        x += 1
    if ax < -200 and x > 0:
        x -= 1

    ay = accelerometer.get_y()
    if ay > 200 and y < 4:
        y += 1
    if ay < -200 and y > 0:
        y -= 1

    display.clear()
    display.set_pixel(x, y, 9)

    sleep(250)

Explanation of the Code

(from Google Gemini Advanced)

Setting Up

  • from microbit import * This line tells the computer to use a module called “microbit” to control the micro:bit.

Our Characters

  • x = 2
  • y = 2 Just like in a story, we have characters x and y. They keep track of where something is shown on the screen, like where a game character might start.

The Main Loop (Happens Repeatedly)

  • while True: This line says, “Keep doing the things inside this block of code over and over again!”

Sensing Movement

  • ax = accelerometer.get_x()
  • ay = accelerometer.get_y() The micro:bit has a special sensor to detect how it’s tilted. These lines find out how much it’s tilted sideways (ax) and up-and-down (ay).

Moving Right

  • if ax > 200 and x < 4: If… the micro:bit is tilted a lot to the right (more than a number 200) and our character x isn’t all the way to the right edge (less than a number 4), then…
    • x += 1 This line moves our character x one step to the right.

Moving Left, Up, and Down (Similar to Moving Right)

These parts of the code work similarly to how we checked for moving right.

Drawing and Clearing

  • display.clear() This line erases anything that was previously shown on the micro:bit’s tiny screen.
  • display.set_pixel(x, y, 9) This line draws a bright dot (because 9 means bright) on the screen.

Short Pause

  • sleep(250) This line tells the computer to wait.

2024-03-26

Computing in the News

U.S. hits Apple with landmark antitrust suit, accusing tech giant of stifling competition

Tinkercad Circuits

2024-04-09

Computing in the News

Google to destroy billions of data records to settle “incognito” lawsuit

Tinkercad Circuits

Self-Directed Learning

2024-04-11

Snap!

2024-04-16

Computing in the News

35-gram Hopcopter revolutionizes robotics with its hops and flight

Snap!

Self-Directed Learning

2024-04-18

Snap! Clones

Self-Directed Learning

2024-04-23

Computing in the News

“The Impossible Statue” Uses AI To Blend The Styles Of Five Master Sculptors

Practice Quiz on Kahoot

Self-Directed Learning

2024-04-23

Python in repl.it

We’ll use repl.it to write and run Python code.

Here’s the code we wrote, with comments and an explanation added by Gemini Advanced:

# This line prints the classic message 'Hello, world!' to the screen
print('Hello, world!')

# This line asks the user to input their favorite team and stores it in a variable called 'team'
team = input('Favorite team? ')

# This 'if' statement checks if the team entered is exactly 'Warriors'
if team == 'Warriors':
    # If it is, this line prints a positive message
    print('Good choice!')

# This 'elif' statement checks if the team entered is exactly '49ers'
elif team == '49ers':
    # If it is, this line prints a slightly less enthusiastic message
    print('Oh, them?')

# This 'else' statement runs if none of the above conditions were met
else:
    # This line indicates the user picked a team the program doesn't recognize
    print("I don't know that team.")

print() function: This tells the computer to display text on the screen.

Comments: Lines starting with # are ignored by the computer, but they help humans understand the code.

input() function: This lets the user type something in and stores it.

Variables: These are like containers for storing information (in this case, the user’s favorite team).

if/elif/else statements: These control the flow of the program.

  • The code checks different conditions one after the other.
  • Only the code block of the first matching condition will run.

Self-Directed Learning