Discussion 0: Getting Started

This is an online worksheet that you can work on during discussions. Your work is not graded and you do not need to submit anything. The last section of most worksheets is Exam Prep, which will typically only be taught by your TA if you are in an Exam Prep section. You are of course more than welcome to work on Exam Prep problems on your own.


The vitamin for Discussion 0 is just completing the Syllabus quiz, which can be found here.

Lost on the Moon

Your spaceship has just crashed on the light side of the moon. You were scheduled to rendezvous with a mother ship 200 miles away on the lighted surface of the moon, but the rough landing has ruined your ship and destroyed all the equipment on board except for the 15 items listed below. (Note: you are able to consume food/water/medicine inside your space suit).

Your crew's survival depends on reaching the mother ship, so you must choose the most critical items available for the 200-mile trip. Your task is to rank the 15 items in terms of their importance for survival. Place a number 1 by the most important item, number 2 by the second most important, and so on, through number 15, the least important.

Item Your Rank (1) Group's Rank (2) NASA's Rank (3) | (3) - (1) | | (3) - (2) |
Box of matches
Food concentrate
50 feet of nylon rope
Parachute silk
Solar-powered portable heating unit
Two .45 caliber pistols
One case of dehydrated milk
Two 100-pound tanks of oxygen
Stellar map (of the moon's constellations)
Self-inflating life raft
Magnetic compass
5 gallons of water
Signal flares
First-aid kit containing injection needles
Solar-powered FM receiver-transmitter

Secrets to Success in CS 61A

CS 61A is definitely a challenge, but we all want you to learn and succeed, so here are a few tips that might help:

  • Ask questions. When you encounter something you don't know, ask. That is what we are here for. This is not to say you should raise your hand impulsively, but you are going to see a lot of challenging stuff in this class, and you can always come to us for help.
  • Study in groups. Again, this class is not trivial; you might feel overwhelmed going at it alone. Send a message and reach out to other students in the class! Work together, either on homework, on lab, or for midterms, as long as you don't violate the cheating policy!
  • When stuck on a problem, try to explain the area in which you are stuck. This doesn't need to be to a person who understands how to solve the problem (or even a person! This practice is often referred to as rubber ducking because you can talk to a rubber duck) because the main goal is for you to clarify your own thoughts and figure out what exactly is wrong with your understanding or code.
  • Go to office hours. Office hours give you time with the instructor or TAs by themselves, and you will be able to get some (nearly) one-on-one instruction to clear up confusion. You are not intruding; the instructors and TAs like to teach! Remember, if you cannot make office hours, you can always make separate appointments with us!
  • Do (or at least attempt seriously) all the homework. We do not give many homework problems, but those we do give are challenging, time-consuming, and rewarding.
  • Do all the lab exercises. Most of them are simple and take no more than an hour or two. This is a great time to get acquainted with new material. Come to office hours if you need more guidance!
  • Optional lab questions are 'optional' in the sense that they are extra practice, not that they are material that's out of scope. Make sure you do them if you have time!
  • When preparing for the midterms and final, do past exam questions! Lecture, lab, and discussion provide a great introduction to the material, but the only way to learn how to solve exam-level problems is to do exam-level problems.
  • Most importantly, have fun!

Python Basics (Optional)

Primitive Expressions

A primitive expression requires only a single evaluation step. Literals, such as numbers and strings, evaluate to themselves. Names require a single lookup step (see the Assignment statements section below).

>>> 2
>>> 'Hello World!'
'Hello World!'

Arithmetic Expressions

Arithmetic expressions in Python are very similar to ones we've seen in other math contexts. They involve binary arithmetic operators +, -, *, /, //, %, and **) and follow PEMDAS rules.

>>> 6 + 2 * 5
>>> 9 // 2     # Floor division (rounding down)
>>> 9 % 2      # Modulus (remainder of 9 // 2)
>>> (3 + 2) * 4 // 3
>>> 4 ** 3     # Exponent

Assignment Statements

An assignment statement assigns a certain value to a variable name.

For example, in:

x = 2 + 3

x is the variable name, and 2 + 3 is the expression that evaluates to the value 5. This assignment statement assigns 5 to x.

To execute an assignment statement:

  1. Evaluate the expression on the right-hand-side of the statement to obtain a value.
  2. Bind the value to the name on the left-hand-side of the statement.

Let's try to assign the primitive value 6 to the name a, and subsequently do a lookup on a.

>>> a = 6
>>> a

Now, let's reassign a to another value. This time, let's use a more complex expression. Note that the name is bound to the value, not the expression!

>>> a = (3 + 5) // 2
>>> a


Q1: What would Python display?

What would Python display?
>>> 3 + 4 ** 2
>>> a = 6 + 2 * 4
>>> a
>>> b = (2 + 2) * 2 + 3 % 2
>>> b
>>> a + 2 * b
>>> b += a      # Equivalent to b = b + a
>>> a
>>> b