+ All Categories
Home > Documents > Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141...

Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141...

Date post: 22-Aug-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
54
Grandparents U, 2017 Part 1 Computer Programming for Beginners Filip Jagodzinski
Transcript
Page 1: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

Grandparents U, 2017Part 1

Computer Programming for Beginners

Filip Jagodzinski

Page 2: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Preliminaries : Course Website

All of these slides will be provided for you online ...

... So for the time being just relax and listen!

Page 3: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Introduction

Who here has played Pokemon Go?

Page 4: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Introduction

Who here has played Pokemon Go?

What about Super Mario Brothers?

Candy Land?

Page 5: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Introduction

Who here has played Pokemon Go?

What about Super Mario Brothers?

Candy Land?

Q: How are such games

made?

Page 6: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Learning how to Program …

Computer programming is done using a computer

• CODE, or “coding”

• You learn by making mistakes, sort of like learning how to ride the bicycle

Q: How many people were

involved in making Pokemon Go

Page 7: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Learning how to Program …

Computer programming is done using a computer

• CODE, or “coding”

• You learn by making mistakes, sort of like learning how to ride the bicycle

Hundreds!

Q: How many people were

involved in making Pokemon Go

Page 8: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Learning how to Program …

Learning how to program is like learning a new language

• You learn by making mistakes• Then you try some more

Page 9: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Learning how to Program …

Learning how to program is like learning a new language

• You learn by making mistakes• Then you try some more• Then you make more mistakes

Page 10: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Difficult question : What happens next?

Learning how to Program …

Learning how to program is like learning a new language

• You learn by making mistakes• Then you try some more• Then you make more mistakes• Then you try some more

Page 11: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Learning how to Program …

Learning how to program is like learning a new language

• You learn by making mistakes• Then you try some more• Then you make more mistakes• Then you try some more• Then you make bigger mistakes and everything breaks

Page 12: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Programming … is an art and a science

Q: These all depict programs … what do they have in common? How are they different?

Programs (apps) on your smartphone

A nice game of thermonuclearwar

A simple python program

Page 13: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Programming … is an art and a science

Solutions:(as perceived by the end-

user)

Page 14: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Programming … is an art and a science

Solutions:(as perceived by the end-

user)

Programs:(implementation

of a program)

Page 15: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

CPU – The “brain” of the computer

CPUCentral Processing Unit

Q: What does a CPU “do”?Q: How does a CPU work?

Page 16: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

CPU – The “brain” of the computer

CPUCentral Processing Unit

Q: What does a CPU “do”?Q: How does a CPU work?

Instruction(input)

Result(output)

Page 17: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

CPU – The “brain” of the computer

Instruction(input)

Result(output)

That’s what we want to write … the “instructions” for a computer so that when the computer runs our

program the program behaves as designed

Page 18: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Our goals – Overview of the Course

Write a program that prints “Hello world” to the screen

Write a program to store and display your name and age

Page 19: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Our goals – Overview of the Course

Write a program that prints “Hello world” to the screen

Write a program to store and display your name and age

Write a program to predict what clothing you should wearAI

Page 20: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Our goals – Overview of the Course

Write a program that prints “Hello world” to the screen

Write a program to store and display your name and age

Write a program to predict what clothing you should wear

Write a program that prints your name to the screen using turtles

AI

DEMO

Page 21: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

The programming language that we’ll be using …

Page 22: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

print

Luckily, python has many built in functions – these are features of a program that somebody else has written, and which you will use to build your custom program

One of the most basic function is named print … here’s how you use it

Page 23: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

Variables are one of the most basic parts of ANY program and ANY programming language … why do we need them?

Page 24: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

Variables are one of the most basic parts of ANY program and ANY programming language … why do we need them?

Computers are really good at storing (and “remembering”) information (data).

Humans on the other hand are

pretty lousy at it

Page 25: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

A variable is a name that refers to a value. Computers can store (remember) many values, hence a program can have many (millions, if the conditions are

right), of variables

When you (a human) try to “remember” something, you

make associations

Q: how does a computer program “remember” things

Page 26: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

A variable is a name that refers to a value. Computers can store (remember) many values, hence a program can have many (millions, if the conditions are

right), of variables

When you (a human) try to “remember” something, you

make associations

• My mom’s hair color is blond• My dog’s name is Emma• I teach at WWU

Q: how does a computer program “remember” things

Page 27: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

A variable is a name that refers to a value. Computers can store (remember) many values, hence a program can have many (millions, if the conditions are

right), of variables

When you (a human) try to “remember” something, you

make associations

• My mom’s hair color is blond• My dog’s name is Emma• I teach at WWU

My mom’s hair color …

My dog’s name …

I teach at …

EMMA

Q: how does a computer program “remember” things

Page 28: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

A variable is a name that refers to a value. Computers can store (remember) many values, hence a program can have many (millions, if the conditions are

right), of variables

It is a three step process … you must come up with a name for a variable, and assign it a value

Q: how does a computer program “remember” things

Page 29: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

A variable is a name that refers to a value. Computers can store (remember) many values, hence a program can have many (millions, if the conditions are

right), of variables

Step 1 … come up with

variable names

Q: What are good variable names to hold the data

“blond”, “Emma” and 34

My mom’s hair color …

My dog’s name … EMMA

My favorite number … 34

Q: how does a computer program “remember” things

Page 30: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

A variable is a name that refers to a value. Computers can store (remember) many values, hence a program can have many (millions, if the conditions are

right), of variables

myMomsHairColor

myDogsName

faveNum

My mom’s hair color …

My dog’s name … EMMA

My favorite number … 34

Q: how does a computer program “remember” things

Page 31: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

A variable is a name that refers to a value. Computers can store (remember) many values, hence a program can have many (millions, if the conditions are

right), of variables

myMomsHairColor

myDogsName

faveNum

Step 2 : use the assignment operator to

“set” the value of a variable

My mom’s hair color …

My dog’s name … EMMA

My favorite number … 34

Q: how does a computer program “remember” things

Page 32: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

A variable is a name that refers to a value. Computers can store (remember) many values, hence a program can have many (millions, if the conditions are

right), of variables

myMomsHairColor =

myDogsName =

faveNum =

My mom’s hair color …

My dog’s name … EMMA

My favorite number … 34

Q: how does a computer program “remember” things

Page 33: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

A variable is a name that refers to a value. Computers can store (remember) many values, hence a program can have many (millions, if the conditions are

right), of variables

myMomsHairColor =

myDogsName =

faveNum =

Step 3 : to the right of the assignment

operation you place the value that you

want to assign to the variable name on the

left

My mom’s hair color …

My dog’s name … EMMA

My favorite number … 34

Q: how does a computer program “remember” things

Page 34: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

A variable is a name that refers to a value. Computers can store (remember) many values, hence a program can have many (millions, if the conditions are

right), of variables

myMomsHairColor = “blond”

myDogsName = “Emma”

faveNum = 34

Q: how does a computer program “remember” things

Now you can use the variable in your program, and the

computer will know it is referring to the data that you

assigned to that variable

Page 35: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Variables

Putting it all together, what does the below program do when you run it?

Page 36: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

The input function

One other important function in python is named input

Use it to ask the user to provide an answer to a question, which you can then store in a variable

Page 37: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Doing something over and over again …

Humans are also really good at making mistakes if we are tired or doing something over and over again … but computers are REALLY good at

doing something over and over again

Write a program that prints “Hello”

9 times

But there’s an easier way!

Page 38: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Doing something over and over again …

Humans are also really good at making mistakes if we are tired or doing something over and over again … but computers are REALLY good at

doing something over and over again

Write a program that prints “Hello”

9 times

But there’s an easier way!

Page 39: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Doing something over and over again …

Humans are also really good at making mistakes if we are tired or doing something over and over again … but computers are REALLY good at

doing something over and over again

Write a program that prints “Hello”

9 times

But there’s an easier way!

Page 40: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Doing something over and over again …

Humans are also really good at making mistakes if we are tired or doing something over and over again … but computers are REALLY good at

doing something over and over again

Write a program that prints “Hello”

9 times

But there’s an easier way!

Page 41: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Doing something over and over again …

Humans are also really good at making mistakes if we are tired or doing something over and over again … but computers are REALLY good at

doing something over and over again

Write a program that prints “Hello”

9 times

But there’s an easier way!

Page 42: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Doing something over and over again …

Humans are also really good at making mistakes if we are tired or doing something over and over again … but computers are REALLY good at

doing something over and over again

Write a program that prints “Hello”

9 times

But there’s an easier way!

Page 43: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Doing something over and over again …

For this morning’s task, write a program that

asks you to input your name, your age, and

prints that information to the screen 15 times

Page 44: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Conditional

One neat thing about programs is that they seem to be “smart”

Goal : Write a program that will tell you want clothing to wear

Page 45: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Conditional

One neat thing about programs is that they seem to be “smart”

Goal : Write a program that will tell you want clothing to wear

If you want your program to be intelligent, use if

Page 46: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Conditional

One neat thing about programs is that they seem to be “smart”

Goal : Write a program that will tell you want clothing to wear

age = int(input(“what is your age”))

if (age > 10) :

print(“you are older than 10 years”)

Page 47: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Conditional

One neat thing about programs is that they seem to be “smart”

Goal : Write a program that will tell you want clothing to wear

age = int(input(“what is your age”))

if (age > 10) :

print(“you are older than 10 years”)

If the input is a number, use the int function in combination with input

Page 48: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Conditional

One neat thing about programs is that they seem to be “smart”

Goal : Write a program that will tell you want clothing to wear

age = int(input(“what is your age”))

if (age > 10) :

print(“you are older than 10 years”)

The if is used to check whether something is true or not

Page 49: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Conditional

One neat thing about programs is that they seem to be “smart”

Goal : Write a program that will tell you want clothing to wear

age = int(input(“what is your age”))

if (age > 10) :

print(“you are older than 10 years”)

The code inside the if is run ONLY If the if statement was true

Page 50: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Conditional

One neat thing about programs is that they seem to be “smart”

Goal : Write a program that will tell you want clothing to wear

age = int(input(“what is your age”))

if (age > 10) :

print(“you are older than 10 years”)

raining= input(“is it raining”)

temp = int(input(“what is the temp”))

if (raining == “yes” and temp < 40) :

print(“wear a hat, globes, and jacket!”)

Page 51: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Conditional

One neat thing about programs is that they seem to be “smart”

Goal : Write a program that will tell you want clothing to wear

age = int(input(“what is your age”))

if (age > 10) :

print(“you are older than 10 years”)

raining= input(“is it raining”)

temp = int(input(“what is the temp”))

if (raining == “yes” and temp < 40) :

print(“wear a hat, globes, and jacket!”)

Check the value of a variable by using the double equal sign!

Page 52: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Conditional

One neat thing about programs is that they seem to be “smart”

Goal : Write a program that will tell you want clothing to wear

age = int(input(“what is your age”))

if (age > 10) :

print(“you are older than 10 years”)

raining= input(“is it raining”)

temp = int(input(“what is the temp”))

if (raining == “yes” and temp < 40) :

print(“wear a hat, globes, and jacket!”)

Use and to check the values of several things. The above code checks if the variable raining has the value “yes” and the temperature is less than 40

Page 53: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Doing something over and over again …

For your second program, you’ll write a program that asks what temperature it is

and whether it is raining, and it will tell you what clothing

to wear!

Page 54: Grandparents U, 2017 Part 1 - Western Washington Universityjagodzf/teaching/...Pokemon Go. CSCS 141 Computer Programming I ... A nice game of thermonuclear war A simple python program.

CSCS 141Computer Programming I

Hands-on exercises in the lab!

Up Next


Recommended