Week2VariablesMathComments.pdf


Preview of PDF document week2variablesmathcomments.pdf

Page 1 2 3 4 5 6 7 8

Text preview


RHHS Compsci 2016

Week 2 - October 6th

Variables, Math, Comments

REVIEW
Do you still remember stuff from last week?

USING IDLE
CONSOLE
When you first launch IDLE, you will be in interactive mode.
This above image is what you will see, where you can enter a
single line of a command, and it will run immediately, without
any need to save or compile.
In interactive mode, you can only run single lines of code.

EDITOR
You have to be editing a file to be in scripting mode. This mode
lets you enter multiple lines of code, and you will have to save
it as a .py before you can run it. When you run the program, it
will open a new window. You can find the run command
under the “Run” menu, followed by “Run module,” or simply
press F5 on your keyboard.

VARIABLES
Variables are essentially locations in memory that ​store your
data​. They can be accessed and modified as many times as
you want. To declare a variable, simply state the name you want to use for your variable and
assign it data using the ​= sign. For example, a​ ge = 16​. Make sure the ​variable name is on the
left and the value on the right​. To change or access it later on, just declare the variable again
with whatever you want to change the value to. (ex. ​age = age + 1​)
It is important to write descriptive variable names so that in larger programs the function of a
variable is very clear to the programmer when looking back. (​ex. noOfTurkeys as opposed to
turks​)

Camel Case
This example has two variables declared. (These
will be explained soon.) Note how the difference in
capitalization in the variable names produces two
different variables. Also, note how the capitalization
is done. The first is in something called “​camelCase​.”
In camel case, we don’t use spaces (variable names
can’t have spaces in them), so we separate multiple
words in the name by capitalizing each first letter