# Class 1 - Studygig

Λογισμικό & κατασκευή λογ/κού

7 Νοε 2013 (πριν από 4 χρόνια και 8 μήνες)

113 εμφανίσεις

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

1

IPO Model

2

Inputs

Outputs

Processing

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 processing

In carrying out the instructions of an algorithm, “computing
agent” manipulates data (or information)

Starts with input
-
> produces output

»
Algorithms

3

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

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

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

Computer Hardware

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

7

Computer Hardware (continued)

Random access memory (RAM)

is also called
internal

or primary

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

8

Computer Software

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

A
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

Computer Software (continued)

10

Genealogy of Common Languages

11

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
:

The programming language for this course.

Note that we are using
Python 3
,
not

Python 2.

12

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

Running Code in the Interactive Shell
(continued)

14

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

Behind the Scenes:

How Python Works

16

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

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

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:

2
31

to 2
31

1

Integer literals are written without commas

19

Floating
-
Point Numbers

Python uses
floating
-
point
numbers to
represent real numbers

Python’s
float

typical range:

10
308

to 10
308

and

Typical precision: 16 digits

20

Floating
-
Point Numbers (continued)

21

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

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