some basics see chapters 1 & 2 describe the basic features of an algorithm

24
Some Basics See Chapters 1 & 2 Describe the basic features of an algorithm Explain how hardware and software collaborate in a computer’s architecture Give a brief history of computing Run a simple Python program Strings, integers and floating point numbers Initialize and use variables with 1

Upload: ivory

Post on 14-Feb-2016

23 views

Category:

Documents


2 download

DESCRIPTION

Some Basics See Chapters 1 & 2 Describe the basic features of an algorithm Explain how hardware and software collaborate in a computer’s architecture Give a brief history of computing Run a simple Python program Strings, integers and floating point numbers - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

1

Some Basics

See Chapters 1 & 2

Describe the basic features of an algorithm Explain how hardware and software collaborate in a

computer’s architecture Give a brief history of computing Run a simple Python program Strings, integers and floating point numbers Initialize and use variables with appropriate names

Page 2: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

IPO Model

2

Inputs Outputs

Processing

Page 3: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Fundamentals of Computer Science: Algorithms and Information Processing

Computer science focuses on a broad set of interrelated ideas– Two of the most fundamental ones are:

» Information processingIn carrying out the instructions of an algorithm, “computing agent” manipulates data (or information)Starts with input -> produces output

» Algorithms

3

Page 4: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Algorithms

Steps for determining change when paying for something (i.e., subtracting two numbers):– Step 1: Write down the numbers, with larger number above

smaller one, digits column-aligned from right– Step 2: Start with rightmost column of digits and work your way

left through the various columns– Step 3: Write down difference between the digits in the current

column of digits, borrowing a 1 from the top number’s next column to the left if necessary

– Step 4: If there is no next column to the left, stop» Otherwise, move to column to the left; go to Step 3

The computing agent is a human being

4

Page 5: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Algorithms (continued)

Sequence of steps that describes each of these computational processes is called an algorithm

Features of an algorithm:– Consists of a finite number of instructions– Each individual instruction is well defined– Describes a process that eventually halts after arriving

at a solution to a problem (or so we hope :-D )– Solves a general class of problems

5

Page 6: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

The Structure of a Modern Computer System

A modern computer system consists of hardware and software– Hardware: physical devices required to execute

algorithms – Software: set of these algorithms, represented as

programs in particular programming languages

6

Page 7: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Computer Hardware

Computers can also communicate with the external world through various ports that connect them to networks and to other devices

7

Page 8: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Computer Hardware (continued)

Random access memory (RAM) is also called internal or primary

External or secondary memory can be magnetic, semiconductor, or optical

8

Page 9: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Computer Software

A program stored in computer memory must be represented in binary digits, or machine code

A loader takes a set of machine language instructions as input and loads them into the appropriate memory locations

The most important example of system software is a computer’s operating system– Some important parts: file system, user interfaces

(terminal-based or GUIs) Applications include Web browsers, games,

etc.9

Page 10: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Computer Software (continued)

10

Page 11: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

11

Genealogy of Common Languages

Page 12: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Getting Started with Python Programming

Early 1990s: Guido van Rossum – invented the Python programming language

Python is a high-level, general-purpose programming language for solving problems on modern computer systems

Useful resources at www.python.org Extensive Python documentation at python.org/doc/ Python 3.2: www.python.org/download/releases/3.2.3

The programming language for this course. Note that we are using Python 3, not Python 2.

12

Page 13: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Running Code in the Interactive Shell

Python is an interpreted language Simple Python expressions and statements can

be run in the shell– Easiest way to open a Python shell is to launch the

IDLE or WING– Shell is useful for:

» Experimenting with short expressions or statements Do this! You can’t break the computer by doing so!

» Consulting the documentation

13

Page 14: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Running Code in the Interactive Shell (continued)

14

Page 15: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Input, Processing, and Output

Programs usually accept inputs from a source, process them, and output results to a destination– In terminal-based interactive programs, these are the

keyboard and terminal display

15

Page 16: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Behind the Scenes:How Python Works

We will talk more about this next class!

16

Page 17: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Data Types & Assignments Text processing is by far the most common

application of computing– E-mail, text messaging, Web pages, and word

processing all rely on and manipulate data consisting of strings of characters

Although the first applications of computers were to crunch numbers

The use of numbers in many applications is still very important

17

Page 18: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Data Types & Assignments (cont’d) A data type consists of a set of values and a

set of operations that can be performed on those values

18

Page 19: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Integers

In real life, the range of integers is infinite A computer’s memory places a limit on

magnitude of the largest positive and negative integers– Python’s int typical range: –231 to 231 – 1

Integer literals are written without commas

19

Page 20: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Floating-Point Numbers

Python uses floating-point numbers to represent real numbers

Python’s float typical range: –10308 to 10308 and Typical precision: 16 digits

20

Page 21: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Floating-Point Numbers (continued)

21

Page 22: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Variables and the Assignment Statement

A variable refers to a value in the memory– Makes it easy to remember and use later in program

Variable naming rules:– Reserved words cannot be used as variable names

» Examples: if, def, and import– Name must begin with a letter or _ (underscore)– Name can contain any number of letters, digits, or _– Names are case sensitive

» Example: WEIGHT is different from weight

22

Page 23: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

Variables and the Assignment Statement (continued)

Programmers use all uppercase letters for symbolic constants– Examples: TAX_RATE and STANDARD_DEDUCTION

Variables receive initial values and can be reset to new values with an assignment statement<variable name> = <expression>

23

Page 24: Some Basics See Chapters 1 & 2 Describe the basic features of an  algorithm

24

Required Readings

Fundamentals of PythonSections 1.4, 1.4.1, 1.4.2, 2.3.1, 2.3.5, 2.4.1, 2.4.2.