OpenBrackets
Beginning Programming
Week 2 Day 1
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
Previously on OB...
Remember 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
Operators are for doing math (and more) with values
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"
More ways to share - you can do "multiplayer" on repls
2) Then share the link
Group exercise - write MadLib code
Values and operators can be grouped with ()
2 + 2 * 3
( 2 + 2 ) * 3
4 * 3
( 2 + 2 ) * ( int(input()) + 1 )
Some more types
Can you make one of each of these, and test with type()?
Some operators work with int and str values
You can combine strings using the + operator
How can you combine a str and an int?
You can convert any int into a str using str() function
type(12)
type(str(12))
"there are " + 12
"there are " + str(12)
You can convert any str into a int using int() function
"there are " + str( 12 + int("12") )
Group exercise - write a Time Factorializer
Ask the user to enter their age in years.�Print out:
Make sure to print out text labelling which is which. Work together!
The Error-o-dex
5 minute break!
Let's actually make a game!
Carl the Goblin is trying to "liberate" an book of spells from a private library guarded by trolls
...however...
Carl is not a warrior
Carl does know some illusion spells though!
Can Carl make the right choices to sneak in and get the book?
Logical operators can check if values are equal or not
Operators like == and != return values like True and False
These are called "boolean" or "logical" values
== and != are operators
You can test if values are equal - or not !
choice = "A"
print( choice )
print( choice == "A" )
print( "choice is equal to A: " + (choice == "A") )
print( "choice is equal to A: " + str(choice == "A") )
print("choice is not equal to A: "+str(choice != "A"))
print(type(choice != "A"))
bool aka boolean aka logical
type(True)
type(False)
True == True
True == False
False == False
Reminder:
You can test things out in the console
Click in Console, type, and press enter
Difference: everything is "print"-ed out to you�'Run' code is not automatically "print"-ed
Conditionals are how your program "thinks"
For examples, try these blocks, and change them to change the behavior:
if True:
print("true is true")
if False:
print("false is true")
Indentation is important!!
What is wrong with the code below?�
if True:
print("huh?")
IndentationError: expected an indented block
How to fix it? Add tab/spaces before print to indent it
if True:
print("huh yeah")
Exercise
What should this code produce?
if 2 + 2 == 3:� print("2 + 2 is 3")�
condition = 2 + 2 == 3�if condition:� print("2 + 2 is 3")
How do we ask if the user likes apples, and print "you like apples" if they respond yes?�Remember the input() function?
if true - or else !
else: is something you can put under an if condition:
if the if condition: is not true, the else: will run
What should this code produce?
if 2 + 2 == 3:� print("2 + 2 is 3")�else:� print("2 + 2 is not 3")
Write a choice-adventure game
Group exercise
_nnnn_
dGGGGMMb
@p~qp~~qMb
M|@||@) M|
@,----.JM|
JS^\__/ qKL
dZP qKRb
dZP qKKb
fZP SMMb
HZM MMMM
FqM MMMM
__| ". |\dS"qML
| `. | `' \Zq
_) \.___.,| .'
\____ )MMMMMP| .'
`-' `--'
Can you draw something by printing strings? ----->
Work together to draw a picture of an animal (or animals)
Copy and paste! Share!
What letters / symbols work best?
How do you do lots of lines?
Starfish? Fish? Bat? Snail? Crab? Worm? Cat? Dog?
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!