
Code world 201
Living in a world where the separation between man and computer is increasingly blurry.
Learning to code makes us masters of technology.
What we are doing today
Last class, we explored the fundamentals of coding.
First we made computers speak.
Then we taught it to remember things.
We're going to kick it up a notch and create our first human/computer conversation. By opening the lines of communication, we can teach computers to interact with us.
Today, we are going to teach computers to listen.

Exercises: Review
-
Copy and paste this code into your Replit.
print('Hello, world!')
This is the print() statement.
-
Make the computer print these lines of text.
What did the fish say when he ran into a wall?
Dam.
-
Predict what each print() statement will display.
president = "Abe Lincoln"
print(president)
print("president")
-
Combine these two values then print them. It should print "260".
distance_to_barstow = 120
distance_to_vegas = 140
How do computers listen?
When computers are taught to listen, they can do amazing things for us.
-
They can scour the internet for us.
-
They can summon a cab to our front door.
And it all starts from a single line of code.

Exercises: Information in / Information out
-
Copy and paste this code into your Replit.
name = input("Favorite singer: ")
print(name)
input() sends whatever the user typed into the console into the variable name. Your console should look like this:
Favorite singer: selena gomez
selena gomez
We will mark the input label (e.g. "Favorite singer") in green.
-
Your turn! Create this:
How old are you: 51
51
-
Fix the bug! The code below doesn't work.
temp = input("Current temperature: ")
print(temperature)
Fix the problem so that it does this:
Current temperature: 84
84
-
Full name generator. Notice it prints the full name twice!
First name: Taylor
Last name: Swift
Taylor Swift
Taylor Swift
-
Code prediction! Predict what this code will do before you run it.
print("Sum it up!")
first_addend = input("First number: ")
second_addend = input("Second number: ")
total = first_addend + second_addend
print(total)
* This code acts funny. Don't try to fix it! We'll show you how to fix it later.
It's a big world after all
Just like how there are different types of vegetables at the farmer's market, there are different types of data.
The two we are going to use today are Strings and Integers:
-
Strings are for text.
"Hello World!"
-
Integers are for numbers.
123123

Quiz: Name the data type!
-
theater = "AMC theater"
- height = 52
- weight = "251 lbs"
- speed = "85"
Changing data types
In our last exercise, our app behaved like this:
Sum it up!
First number: 12
Second number: 34
1234
What happened was there are two ways to add variables, as a String or as an Integer. Our code was adding numbers as if they were Strings!
Fortunately, just like how water can be turned into steam, data types can be changed as well. If we do this right, we can make our Strings add as Integers!
Sum it up!
First number: 12
Second number: 34
46

Exercises: Data Types
-
Compare the two! Take a look at the old code.
print("Sum it up!")
first_addend = input("First number: ")
second_addend = input("Second number: ")
total = first_addend + second_addend
print(total)
Anytime a value comes through input(), it comes in as a string. To fix our problem, we need to cast the value from a String into an Integer.
print("Sum it up!")
first_addend = input("First number: ")
second_addend = input("Second number: ")
total = int(first_addend) + int(second_addend)
print(total)
-
Bill calculator. Add your bill together.
Total cost: 49
Taxes: 4
53
-
Fix the bug! This code doesn't work. Help me fix it!
sarah = "186"
sally = "159"
total = int(sarah_score + sally_score)
print(total)
-
Restaurant calculator. Calculate everyone's fair share!
Food bill: 20
Number of people: 4
5
-
Fix the bug! This code doesn't work. Help me fix it!
age = int(current_year - birth_year)
birth_year = input("What year were you born? ")
current_year = input("What year is it? ")
print(age)
-
Miles calculator. Calculate how many miles we got left in the tank.
Gallons left in tank: 7
Miles per gallon: 25
175