OpenBrackets
Beginning Programming
Week 1 Day 2
Welcome!
Welcome to class!
This is the Starting Programming class
Have a question?
Ask a teacher or TA
Type in chat
Or
Or un-mute and speak up
Open up your repl from last time
Modify it to say hello Wednesday
Values
Example of a function and a value
print("hello world")
print�is a function
functions require a ( and a )
a string value is letters between two "" or ''
Another function is input
input()
input() just waits for you to press enter...
Great way to make the program pause
We will use this to get user input, later!
Values have different types
"three" # this is a str�3 # is an int
# You can check the type with the�# type function:
type("three")�type(3)
str values
Letters within quotes ("" or '') are a str (string) value
Without quotes, python thinks the�letters are a "variable" that is probably�"not defined"
>>> "abc"
'abc'
>>> abc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'abc' is not defined
int values
Whole integer numbers alone are ints , in quotes become str
3
"3"
You can turn an int into a str with str()
str(3)
You can turn a str into an int with int()
int("3")
It would be nice if the computer could remember values...
You can store values in variables
Variables have a name
Like labelling a new place on a bookshelf
Don't put the name in quotes, just put something in that place
Get the value back out from the variable!
Of course, you can also go get the value from the variable
To do this, you just use the variable's name.
Assign a value to a variable with =
Try this:
Assign 10 to a variable number, then print it out like print(number)
Try changing the value in number to be 12, and print that
Store a string value in a variable called apples and print it out
Use any word for a variable ... except some!
print input
import for
int my_variable
str my_variable_1
Typing into console
Typing into editor
2) hit enter (or cntrl+enter)
3) only the "print()"-ed� values are printed
How do you print it out though?
If you ask for type with type() in editor, then it doesn't print it out.�
type() turns into the value that shows what type
You can put this value inside of other�functions, like print()
Using input()
If you ask for input with input() ,�it turns into the value that was entered
You can put this value inside of other�functions, like type() and print()
Exercise
Put together types, type(), input(), and print() to:
Make a program that asks for input ( using input() ) �and prints out what type ( using type() )�of input was entered.
What types are these inputs?
3
"three"
True
Exercise
Make a program that
For each of these, print out what direction, then print out how many steps.
Make sure the steps are an int !
Exercise
Update your program
At the end, print the direction and how many steps.
Operators are for doing math (and more) with values
Try solving some problems with int values:
What is 2+2?� Four times thirteen?� If I get paid $50,000 in a year, � how much is that per month?
A small portion of code is called an "expression"
Here's some more expressions to try --->
1 + 1
55 / 11
3*2
10 - 611
1000000 * 1000000
Symbols like + / - * are called "operators"
Values can be numbers/letters ... or from a variable!
Write code with variables and operators � and int values that tell you:�� If I get paid salary in a year, � how much is that per month?
Try different values of salary, like:
12880� 14500� 30000
When you need help outside class
Email openbracketscoding@gmail.com and say what class and teacher you have
If you are age 13 or older, you can try Discord
The age restriction is because of Discord’s Terms of Service
Thanks for coming to class!
Please let us know if you have any questions!