unit 1 - weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4...

113
UNIT 1 Intro to Python Graphics Computer Hardware

Upload: others

Post on 22-Apr-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

UNIT 1Intro to Python

Graphics

Computer Hardware

Page 2: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

DAY 1Python Introduction

Page 3: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

I can…..

• Identify the 4 functions of a computer.

• Explain what at programming language, why it is used,

and its three types.

• Explain the difference between a compiler and interpreter.

• Write my first python program.

• Use the turtle graphics to create a basic drawing in

Python.

Page 4: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Functions of Computer

• Think – Pair – Share

Brainstorm the following question:

What are the main functions of all computers?

Page 5: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

4 Functions of a Computers

1.Input

2.Process

3.Store

4.Output

Page 6: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

4 Functions of a Computer

1. Input

• Computers take in information from its users

• Examples:

o Keyboard

o Mouse

o Audio

o Touch

2. Process

• Computers “do something” what that information

• Examples

o Calculators perform the inputted mathematical equation

o Phone opens an app when you touch it

Page 7: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

4 Functions of a Computer

3. Store

• Computers store information in memory

• Examples:

o Save a document in Microsoft word

o Cell Phones stores your contacts

o Calculator stores “previous answer”

4. Output

• Computers output information for the user to see

• Examples:

• Audio stounds

• Visually displaying a document on the screen

Page 8: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

What is a computer program?

•A program is a planned sequence

of instructions that tell a computer

what steps to perform and when to

perform them

•A program is also known as computers

software .

Page 9: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Think-Pair-Share

Brainstorm the following:

If writing a program is simply giving a computer

instructions, why can’t we use English? Why do we need

to learn computer languages?

Page 10: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Programming Languages

• Computers follow instructions EXACTLY they

cannot interpret meaning like humans can

• English language is confusing !

• Some words have multiple meanings

• Ex: lead the action and lead the metal

• Some words sounds the same, but spelled differently with different

meanings

• Ex: To, two, too

• Ex: Their, they’re, there

• Each word in a computer programming language has

ONE meaning as a result the computer will know

exactly what to do as it reads each instruction

Page 11: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Programming Languages

• What programming languages have you heard of?!?

Page 12: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Types of Computer Languages

1.High Level Languages

2.Assembly Language

3.Machine Language

Page 13: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

High Level Languages

• Easier for programmer to use – similar to every

language and symbols

• Portable (can be used on different types of computers

without modification)

• Must be translated into something the computer

can understand

• Example Languages:

Pascal C++ Python

FORTRAN C Logo

BASIC C# Ava

COBOL Java

Page 14: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Assembly Language

• Commonly considered a mid -level or low -level language

• While still uses every day language, operations must be given more explicitly .

Example Code snippets:Assembly Language High Level Language

LOAD A C = A + B

ADD B if(x < 5)

STORE C C := A + B

• Actual words and symbols are translated into machine language

Page 15: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Machine Language

• Computer’s native language – the only type of program

a computer understands

• Higher level programs must be translated into machine

language

• Consists of a binary string ( 0 and 1s )

• Examples: 0100 0011 0011 1010

0011 1101 0100 0001

0010 1011 0100 0010

Page 16: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Translating Higher Level Machine

• High-level Language must be translated into machine

language before it can be executed

• A compiler is a program that translates the entire

program from the higher level language to machine

language

• Examples: C++, Pascal, Java

• An interpreter is a program that translates a program

from the higher level language into machine language

one line at a time

• Examples: BASIC, Visual Basic, Python

Page 17: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Programming Language

• Created by Guido van Rossum – released in 1991

• Interpreter language

• Focuses on easy readability

Fun Facts:

• Where did the name come from??

• Author had a love for the British comedy group Monty Python

• IDLE – Integrated DeveLopment Environment

• Eric Idle is one of Monty Python’s founding members

Page 18: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Where Can I find Python??

Page 19: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Two “Modes” of Python

• Interactive Mode - Shell

• Where our code will run/display to

the screen

• Where we can “interact” with our

program

• Will see “shell” across the top

• Script Mode .

• Where we write longer programs

– mostly programming text

• Will see a file path across the top

Page 20: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Interactive Mode - Python Shell

• Open up the Python IDLE Shell

• Shell is where your program will appear when it is run

• Where we can “interact” with our program

• Can Type Single Lines of Instruction

Examples:

>>> print(“Hello computer”) **press enter**

Hello computer

Page 21: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Script Mode - First Python Program

• Where we type programs longer than 1 line

To Create New Program:

File New File

File Save As

name: FirstProgram.py

(**all program names end in py)

Now may type instructions!

Page 22: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

First Python Program

Type the following in your program:

print(“Hello Ms. Wardecke”)

print(“This is my first program”)

print(“It was a success!”)

To Run Program in Shell:

1. Save your program

2. Run Run Module

3. Your program will run in the shell! You should see 3

lines of code!

Page 23: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Commenting

• Commenting is an important part of the programming

process

• Benefits

• Others can read and comprehend the purpose of your code

• Finding errors .

• Remind you of the purpose of each set of code so in a day, month,

year, etc you will still remember the purpose of each line of code!

Requirement:

• You WILL BE required to comment your code!!!

Page 24: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Commenting in Python

# single line comment (hashtag)

“”” multiple line comment (3 double quotes

needed at start and end)

Examples:

“”” Project Name: First Program

Author: Sarah Wardecke

Date: 6/12/17”””

print(“Hello”) # prints hello message to the screen

Page 25: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Where do comments typically go?

• Beginning to introduce a program

• Next to a single line (or a few times) of code to summarize

its purpose

• The end to conclude a program

Let’s go add comments into your first program!

Page 26: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Organizing Files into Folders

• Right Click on your desk top – create a folder entitled

“Computer Science” – open this folder

• Right Click – create a folder entitled “Unit 1” – open this

folder

• Right Click – create a folder entitled “In Class Practice”

Page 27: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Create Unit 1 – Lesson 1 Program

• Open up the Python IDLE

• File New File

• File Save As

• Open up the Folder Path:

Computer Science/Unit 1/In Class Practice

Name: U1L1Graphics

Page 28: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Beginning Code

• Add the following to your program:

**All programs should begin with commenting discussing the

purpose of the program**

# Unit 1 Lesson 1 – Graphics Introduction

# <insert your name here>

Page 29: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Shell

• Dimensions: 700 (width) x 660 (height)

• Middle is point (0,0)

• Works like a coordinate plane in mathematics

(0,0)

Page 30: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Import Turtle Graphics

Type the following into the first line of your program:

import turtle #import turtle graphics

**this line of code imports the turtle graphics into your program.

Without this line of code, you cannot use graphics**

Page 31: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Create a Turtle Pen in your program

Add the following to your program:

tia = turtle.Turtle() # creates a turtle to draw with

# called “tia” you can create a

# turtle of any color your choose

tia.shape(“turtle”) # changes tia to a turtle shape

# rather than an arrow

Page 32: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Turtle Class Functions

• Turtle “pens” have many functions or “actions” – the python language has many built in functions that allows us to mimic a real pen. A few are listed below.

<turtle name>.forward(<#>)

<turtle name>.backward(<#>)

<turtle name>.left(<#>)

<turtle name>.right(<#>)

<turtle name>.width(<#>)

<turtle name>.goto(<x coordinate>, <ycoordinate>)

<turtle name>.pendown()

<turtle name>.penup()

Note: anything with < > symbols around them will be replaced with values unique to the program

Page 33: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Turtle Function Exploration Lab

Follow the Exploration Activity – once everyone is

completed, we will recap as a class!

Page 34: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Turtle Pen Functions

1. <turtle name>.forward(<#>)

• Moves the specified pen forward the numbers of steps (pixels)

specified.

• NOTE: forward = direction the pen is currently facing, NOT a

specific direction

2. <turtle name>.backward(<#>)

• Moves the specified pen backward the number of steps (pixels)

specified

• NOTE: backward = opposite direction the pen is currently facing

Page 35: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Turtle Pen Functions

3. <turtle name>.left(<#>)

• Rotates the specified pen the specified number of degrees left

(counterclockwise)

4. <turtle name>.right(<#>)

• Rotates the specified pen the specified number of degrees left

(counterclockwise)

Remember how degrees work:

360° = full circle 180° = half circle

90° = one four circle/right angle

Page 36: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Turtle Pen Functions

5. <turtle name>.width(<#>)

• Changes the width of the specified pen – the large the number, the

thicker the pen

6. <turtle name>.goto(<xcoord>, <ycoord>)

• Will send the pen to that specified location (remember the

background is an x-y plane)

• Will draw continue to draw a straight line with the pen on the way to

that location!

Page 37: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Turtle Pen Functions

7. <turtle name>.penup()

• Mimics picking the pen up off the paper – pen will not draw again

until placed back down

• You will still see the “turtle tracer” showing you the location of your

pen even when you are not drawing

8. <turtle name>.pendown()

• Puts the pen back down – the pen will now write!

Page 38: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:
Page 39: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

DAY 2Computer Hardware (processing devices)

Python Graphics

Page 40: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

I can…

• Describe the key processing components of a computer.

• Use the turtle graphics to create a basic drawing in

Python.

Page 41: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

The Hardware Parts of a Computer

Input devices

Central Process-ing Unit

Main Memory

Auxiliary Memory

Output devices

Bus / Interface (includes motherboard)

Input Processing Storage Output

Page 42: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Processing Devices

Central Processing Unit

• Also called the CPU .

• The brain of the computer system

• Most complex component of the computer

Our computers:

• Single silicon chip called a microprocessor .

Page 43: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Main Components of the CPU

1. Arithmetic-Login Unit (ALU) :

• Performs:

• Arithmetic calculations (+, -, x, ÷)

• Logical comparisons of two numbers (=, <, >)

• Logical functions (and, not, & or)

Page 44: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Main Components of the CPU

2. Control Unit :

• Controls the workings of the computer through a

sequential “fetch-execute” cycle

• Information is “fetched” from memory and sent to

the ALU

• As the ALU “executes” the command or processes

data, the control unit fetches more data

Page 45: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Main Components of the CPU

3. Registers :

• On-chip memory for temporary storage of data or

instructions

4. Floating Point Processing Unit (FPU) :

• Specialized, optional unit to perform arithmetic

calculations (+, -, x, ÷) on floating point (non-integer)

numbers

Page 46: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Main Components of the CPU

5. Clock :

• Drives operation of the CPU by electrical impulses

originatin from a quartz crystal

• Speed is measured in one of two ways:

• Millions of impulses per section (megahertz or MHz)

• Billions per section (gigahertz or GHz)

Page 47: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Turtle Pen Graphics - Continued

• Finish Exploration 1

• Exercises 1-5

Page 48: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Graphics Exploration 2

Create Unit 1 – Lesson 2 Program

• Open up the Python IDLE

• File New File

• File Save As

• Open up the Folder Path:

Computer Science/Unit 1/In Class Practice

Name: U1L2GraphicsExtended

Page 49: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Beginning Code

• Add the following to your program:

**All programs should begin with commenting discussing the

purpose of the program**

# Unit 1 Lesson 2 – Graphics Extended

# <insert your name here>

import turtle # import graphics

<turtle name> = turtle.Turtle() # create turtle Pen

Page 50: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

More Pen Class Functions

• Now that we’ve learned the basics – let’s extend our

knowledge of the pen class further!

<turtle name>.color(“<color>“) **string

<turtle name>.color(<red#>, <green#>, <blue#>) # = intensity between 0 and 1

<turtle name>.begin_fill()

<turtle name>.end_fill()

<turtle name>.fillcolor(“<color>”)

<turtle name>.circle(<radius>)

<turtle name>.write(“<words>”)

Note: anything with < > symbols around them will be replaced with

values unique to the program

Page 51: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Pen Function Exploration Lab 2

Similar to yesterday - Follow the Exploration Activity – once

everyone is completed, we will recap as a class!

Page 52: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Pen Functions

1. <turtle name>. color(“<color>“)

• Changes the pen color to the specified color in the quotations

• NOTE: some colors may not be recognize by python

2. <turtle name>. color(<#>, <#>, <#>)

• Changes the pen color to the specified color combination

• Each number must be the range of 0 and 1 and represents:

red intensity, green intensity, and blue intensity

(order matters!)

Page 53: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Pen Functions

3. <turtle name>. begin_fill()

• Notes the beginning of an object to be filled in

4. <turtle name>. end_fill()

• Notes the end of an object to be filled in with color

• The shape starts with “begin fill”’ and ends with “end fill”

Page 54: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Pen Functions

5. <turtle name>. fillcolor(“<color>”)

• Changes the “fill shape” color

• NOTE: not all colors will be recognized by python

• Like the pen, can also use the 3 number combination

6. <turtle name>. circle(<radius>)

• Creates a circle where the pen is the bottom of the circle is with a

radius with the specified value

• Remember – radius means distance from the center of the circle to

the outside of the circle

Page 55: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Pen Functions

7. <turtle name>. write(“<words>”)

• Will write the specified words to the screen

Page 56: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:
Page 57: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

DAY 3Computer Hardware - Storage

Python Graphics – continued!

Page 58: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

I can…

• Describe the key storage components of a computer.

• Use the turtle graphics to create a basic drawing in

Python.

Page 59: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

The Hardware Parts of a Computer

Input devices

Central Process-ing Unit

Main Memory

Auxiliary Memory

Output devices

Bus / Interface (includes motherboard)

Input Processing Storage Output

Page 60: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Storage Devices! – TWO TYPES

1. Main Memory , also known as

Internal/Primary Storage .

2. Auxiliary Memory , also known as

External/Secondary Storage .

Page 61: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Main Memory

1. Main Memory , also known as

Internal/Primary Storage :

• Computer chips called microchips which

can hold a certain amount of information

• Each location in memory has an address ,

and can be thought of as a similar to a

mailbox

Page 62: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Types of Main Memory

A.RAM

B.ROM

Page 63: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Types of Main Memory

A. Random Access Memory or RAM .

• Computer’s temporary or working memory

• Stores data in binary ( machine language ) –

electrical impulses like switches that are “on” (1) or

“off” (0)

• Each “switch” is called one bit and it takes eight

bites to form a byte .

• Information in RAM is stored electronically and

therefore is lost when the computer is turned

off.

Page 64: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Types of Main Memory

B. Read Only Memory or ROM .

• Information/programs permanently stores on

certain chips chips can only be read (not

changed like RAM)

• Information stays even after computer turned off

• Contain machine language to control….

• Start-up routines (tell the computer what to do

when turned on)

• Routines to control input/output devices

• Programs to interpret information and carry out

commands

Page 65: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Auxiliary Memory

2. Auxiliary Memory , also known as

External/Seconday Storage :

• Large, permanent files of information stored

outside of computer

Page 66: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Types of Auxiliary Memory

A. Magnetic Tape

B. Magnetic Disk

C. Hard Drive

D. Compact Disc (CD)

E. Flash Memory

Page 67: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Types of Auxiliary Memory

A. Magnetic Tape

• Similar to the recording tape found in reel to reel

recorder or cassette tape

• Data stores sequentially (one after another)

• Very slow to read

• Holds very large quantities of data

Page 68: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Types of Auxiliary Memory

B. Magnetic Disk

• Plastic, coated with metallic oxide

• Information is recorded magnetically .

• Disk drive spins disk, read/write heads record and

play back information

• Disk is formatted into tracks (concentric circles)

and sectors (section of track) for store information

• Data on disk does not need to be store sequentially

• Information retrieved be sending the read/write head

to the location indicated by the disk’s directory

Page 69: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Types of Auxiliary Memory

C. Hard Drive

• Similar to floppy disk, but usually internal to the

computer

• Several disk surfaces and read/write heads

Page 70: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Types of Auxiliary Memory

D. Compact Disks (CD)

• Information is stored optically through a

series of “pits” and flat surfaces read my

lasers

• Information on…

• CD-ROM = permanent

• CD-R = recordable

• CD-RW = recordable and rewriteable

• Very fast and reliable due to lasers (and no

mechanical parts!)

Page 71: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Types of Auxiliary Memory

E. Flash Memory

• Used in memory cards and USB flash drives

• Non-volatile: does not need power to retain

information

• Stores information in an array of floating gate

transistors called “cells”

• Can be accesses much faster than CDs and hard

drives

Page 72: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Memory Storage Devices

Page 73: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Turtle Pen Graphics - Continued

• Finish Exploration 2

• Exercises 6-9

Page 74: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:
Page 75: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

DAY 4Computer Hardware - Input

Python Graphics – continued!

Page 76: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

I can…

• Describe the key input components of a computer.

• Describe the key output components of a computer.

• Use the turtle graphics to create a basic drawing in

Python.

Page 77: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

The Hardware Parts of a Computer

Input devices

Central Process-ing Unit

Main Memory

Auxiliary Memory

Output devices

Bus / Interface (includes motherboard)

Input Processing Storage Output

Page 78: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Input Devices - TPS

With a partner, discuss the following:

Name as many input devices for the

computer as you can think of!

Page 79: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Input Devices

a. Keyboard

b. Mouse

c. Microphone

d. Touch Screen

e. Scanner

f. Digital Camera

g. Video Camera

h. Modem

i. Microphone

j. Network Card

k. Controller

l. USB

Page 80: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Output Devices - TPS

With a partner, discuss the following:

Name as many output devices for the

computer as you can think of!

Page 81: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Output Devices

a. Monitor

b. Printer

c. Audio Speakers

d. Modem

e. USB

f. Touch Screen

g. Network Card

h. Controller

(vibrate)

**note – some devices are

input AND output**

Page 82: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Input-Output TerminologyNOTE: Often, input and output devices are discussed

together, and are sometimes called

I/O devices .

Page 83: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Other Functions Functions

• Extra Functions

<screen name> = Screen()

<screen name>.bgcolor(“<color>”)

<pen name>.circle(<radius>, <degrees>)

<pen name>.dot(<diameter> , <color>)

<pen name>.speed(<integer 0 to 10>)

Note: anything with < > symbols around them will be replaced with

values unique to the program

**Note – you can research more. These are simply the functions we

are covering in our class**

Page 84: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Pen Function Exploration Lab 3

Similar to yesterday - Follow the Exploration Activity – once

everyone is completed, we will recap as a class!

Page 85: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Extra Functions

1. <screen name> = turtle.Screen()

• Creates an object that allows you to control characteristics of the

screen

1. <screen name>.bgcolor(“<color>”)

• Changes the “background” color of the screen

• NOTE: not all colors will be recognized by python

• Like the pen, can also use the 3 number combination

Page 86: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Extra Functions

3. <turtle name>.circle(<radius>, <degrees>)• Creates a part of a circle

• The first number represents the radius of the circle

• The number of degrees discuss how much of the circle to draw

• 360 degrees = full circle

• 180 degrees = half circle

• Can do partial circles

• Starts where and in the direction the pen is currently facing

4. <turtle name>.dot(<diameter> , “<color>”)• Creates a filled in “dot” on the screen

• The first number represents the diameter of the dot

• The second color selects the color of the dot

• Pen in the CENTER of the dot

Page 87: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Python Extra Functions

5. <turtle name>.speed(<integer 0 to 10>)

• Changes the speed at which the pen will draw the instructions you

have given the computer

6. What happens when you create two pens? Will they

draw at the same time? What happens?

Page 88: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:
Page 89: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

DAY 5Computer Hardware – Output

Output in python: print() function

Page 90: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

I can…

• Display text output to the screen using Python.

Page 91: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Open a New Python Program

• File New File

• File Save As

• Name: U1L4Output

Page 92: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Print() function – 3 options

1. print(“<string>”)

• Prints the exact message in the quotations to the screen and

places an “enter” after the string

2. print(“<string>”, “<string>”, ……, “<string>”)

• Prints the messages one after another, the comma “connects” the

strings together

• A space is put in place of every common as it “concatenates” the

strings together

3. print(“”” <string> “””)

• Prints EXACTLY what is inside the triple double quotes, enters and

spaces included

Page 93: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Code the following

Type the following into Python’s script window

print(“Hello, Computer!”)

Page 94: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Code the following

Add the following line of code – note the small difference

print(“Hello” , “Computer!”)

How is this line of printed code slightly different than the

code on the previous slide?

Page 95: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Quotations and commas

Pay close attention to where the quotations are in relation

to the commas

print(“Hello, Computer!”)

**comma inside of quotations = a comma printed to screen**

**comma outside of quotations = “concatenate and add a space”**

print(“Hello” , “Computer!”)

Page 96: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Code the following

Add the following line of code

print(“Hello

Computer!”)

How is this line of printed code slightly different than the

code on the previous slide?

Page 97: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Code the following

Whitespace means something in Python! The code on the

previous slide throws an error! However we can fix this!

print(“”“Hello

Computer!”””)

The triple double quotations tell the computer to print the

message EXACTLY – enters and spaces included!

Page 98: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Code the following

If you want things to line up

print(“”“

Hello

Computer!”””)

Make sure the all lines of text start and end at the same

location!

Page 99: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Code the following

Type the following

print(“”“

__________

\ \

\__________\

“””)

Page 100: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Code the following

If you want things to line up

print(“”“

__________ .

\ \ .

\__________\ .

“””)

Make sure you start and end each line in the same spot

(use period to mark the end of the line)

Page 101: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Practice Drawing In the Shell!

• Using the print() function, create a drawing on the screen

that meets the following specifications

• Has a “Title” at the top naming the drawing

• Creates a drawing of your choice – I would suggest

choosing a basic shape to start (square, rectangle,

hexagon, etc)

• Your drawing must contain at least 7 rows of text to be

displayed on the screen

Page 102: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Open a New Python Program

• File New File

• File Save As

• Name: U1L5OutputExtras

Page 103: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Code the following

Type the following into Python’s script window

print(“My name is: \t Sarah”)

**Note: this is a forward slash: \t (NOT “/t”)**

Predict: What do you think is going to happen??

Page 104: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

\t

In the print statement – the symbols “\t” communicate

something to the computer

print(“My name is: \t Sarah”)

\t = TAB

Page 105: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Code the following

Type the following into Python’s script window

print(“My name is: \n Sarah”)

**Note: this is a forward slash: \n (NOT “/n”)**

Predict: What do you think is going to happen??

Page 106: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

\n

In the print statement – the symbols “\n” communicate

something to the computer

print(“My name is: \n Sarah”)

\n = NEW LINE

Page 107: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Coding Practice

• Write the code that will make the following print to the

screen using ONLY ONE PRINT STATEMENT.

0 1 1 2 3

5 8 13 21 34

55 89 144 233 377

Page 108: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Numbers in the Print Statement

Type the following into Python’s script window

print(“7 + 2”)

Predict: What do you think is going to happen??

Page 109: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Numbers in the Print Statement

Take away the quotations!

print(7 + 2)

Predict: What do you think is going to happen??

Page 110: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Numbers in the Print Statement

• Numbers are different than strings in the print statement!

• Quotations = print characters exactly as written, like a

string

print(“7 + 2”) 7 + 2

• No quotations = computer the math, then print the result

print(7 + 2) 9

Page 111: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Practice

• Write down what the following print statements will print to

the screen – if there will be an error, note “error”

1. print(“7*3 + 4 = “ , 5*5)

2. print(“7*3 + 4 = “ 5*5)

3. print(3*5 + 6)

4. print(hello)

5. print(“my result: “ , 8*6/4)

6. print(14-6 , 15*10 , 16//3)

Page 112: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Practice - Solutions

• Write down what the following print statements will print to

the screen – if there will be an error, note “error”

1. print(“7*3 + 4 = “ , 5*5) 7*3 + 4 = 25

2. print(“7*3 + 4 = “ , 5*5) ERROR – need comma

3. print(3*5 + 6) 21

4. print(“hello”) ERROR – need quotes around string

5. print(“my result: “ , 8*6/4) my result: 12

6. print(14-6 , 15*10 , 16/4) 8 150 4

Page 113: Unit 1 - Weeblymswardecke.weebly.com/uploads/1/7/1/6/17167688/unit_1... · 2019-01-21 · 4 Functions of a Computer 1. Input • Computers take in information from its users • Examples:

Introduce Projects

• Project 1A: Initials

• Project 1B: Smiley Face

• Project 1C: Trapezoid in print statements

• Project 1D: Dream House

• Project 1E: Flags Project