1 of 26

OpenBrackets

Beginning Programming

Week 1 Day 2

Welcome!

2 of 26

Welcome to class!

This is the Starting Programming class

  • 5 - 6:30pm : 5 min break towards the middle�
  • Teachers and TAs are:
    • Aidan, Kevin, Rohan, and Sean

  • No grades - but the more we can help each other learn as a group, the better

3 of 26

Have a question?

Ask a teacher or TA

Type in chat

Or

  1. Click Reactions
  2. Click Raise Hand

Or un-mute and speak up

4 of 26

Open up your repl from last time

Modify it to say hello Wednesday

5 of 26

Values

6 of 26

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 ''

7 of 26

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!

8 of 26

Values have different types

"three" # this is a str3 # is an int

# You can check the type with the�# type function:

type("three")type(3)

9 of 26

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

10 of 26

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")

11 of 26

It would be nice if the computer could remember values...

12 of 26

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

13 of 26

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.

14 of 26

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

15 of 26

Use any word for a variable ... except some!

  • Be careful of what you name your variables.
  • Some words or keywords in python are reserved for the system and cannot be used as a variable name!
  • They will turn into a different color if it is a registered python keyword

print input

import for

int my_variable

str my_variable_1

16 of 26

  1. type code here�press enter

  • result is�AUTOMATICALLY�"echoed"/printed�back at you

Typing into console

17 of 26

  • type code here

Typing into editor

2) hit enter (or cntrl+enter)

3) only the "print()"-ed� values are printed

18 of 26

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()

19 of 26

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()

20 of 26

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

21 of 26

Exercise

Make a program that

  1. asks for a direction:� "Do you go north, south, east, or west?"
  2. asks for a distance:� "How many steps?"

For each of these, print out what direction, then print out how many steps.

Make sure the steps are an int !

22 of 26

Exercise

Update your program

  • asks for a direction:� "Do you go north, south, east, or west?"�Save the value that the input() turns into as a variable!
  • asks for a distance:� "How many steps?"�Save the value that the input() turns into as a variable!

At the end, print the direction and how many steps.

23 of 26

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"

24 of 26

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

25 of 26

When you need help outside class

Email openbracketscoding@gmail.com and say what class and teacher you have

  • Don't email teacher directly.

If you are age 13 or older, you can try Discord

  • https://discord.gg/ZRtk534

The age restriction is because of Discord’s Terms of Service

26 of 26

Thanks for coming to class!

Please let us know if you have any questions!