Lecture 1 Introduction Sep02 2018
Lecture 1 Introduction Sep02 2018
Output
CPU Devices
Input
Devices
Main Secondary
Memory Memory
Functional View of a Computer
• The secondary memory is where your saved program and data reside
• It is a non-volatile storage
• I.e., when the power is turned off,
your program and data will NOT be lost E.g., Hard Disk
Secondary
Memory
Functional View of a Computer
• The main memory is much faster (but more expensive) than the
secondary one, however, it is volatile
• Your program and data are copied from secondary memory to main
memory for efficiency reasons
E.g., Random Access Memory (RAM)
Main Secondary
Memory Memory
Functional View of a Computer
• The Central Processing Unit (CPU) is the “brain” of the computer
E.g., Monitor
E.g., Keyboard Output
and mouse CPU Devices
Input
Devices
Main Secondary
Memory Memory
Functional View of a Computer
Humans interact with computers
E.g., Monitor
via Input and Output (IO) devices
E.g., Keyboard Output
and mouse Information from Input devices Devices
are processed by the CPU and
Input
may be shuffled off to the main or
Devices
secondary memory
• If you want a computer to add two numbers, the instructions that the
CPU will carry out might be something like this:
Load the number from memory location 2001 into the CPU
Load the number from memory location 2002 into the CPU A Lot of
Add the two numbers in the CPU Work!
Store the result into location 2003
High-Level to Low-Level Languages
• In a high-level language like Python, the addition of two numbers can
be expressed more naturally:
c=a+b Much Easier!
Running
Inputs Outputs
Program
Interpreting a High-Level Language
• An interpreter is a software that analyzes and executes the source
code instruction-by-instruction (on-the-fly) as necessary
Source Code
(Program)
Computer
Running An Outputs
Interpreter
Inputs
• When you first start the interpreter program, you may see something
like the following:
A Python prompt indicating that the Python interpreter is waiting for you to give it a command
Writing Python Commands
• Here is a sample interaction with the Python interpreter:
print is a built-in function that >>> print("Hello")
allows displaying information Hello
on screen >>> print("Programming is fun!")
Programming is fun!
When you call the print function, >>> print(3)
the parameters in the parentheses 3
tell the function what to print >>> print(2.3)
2.3
There is only 1 parameter passed to
print here, which is a textual data (or what is referred to as a string)
Writing Python Commands
• Here is a sample interaction with the Python interpreter:
>>> print("Hello")
Hello
>>> print("Programming is fun!")
Another string parameter Programming is fun!
>>> print(3)
3
An integer (int for short) parameter
>>> print(2.3)
2.3
A float parameter
How can we figure out in a program whether a value is an int, float, or string?
The Type Function
• Python provides a special function called type, which allows us to
figure out the data type of any value
>>> type("Hello")
<class 'str'>
>>> type("Programming is fun!")
<class 'str'>
>>> type(3)
<class 'int'>
>>> type(2.3)
<class 'float'>
Summary
• A computer is a universal information-processing machine, which can
carry out any process that can be described in sufficient detail
• The CPU is the brain of the computer that performs simple arithmetic
and logical operations
• Information that the CPU acts on (data and programs) are stored in
main memory (e.g., RAM), while more permanent information are
stored in secondary memory (e.g., disk)
Summary
• Programs are written using a formal notation known as a programming
language
• There are many different languages, but all share the property of having a
precise syntax (form) and semantics (meaning)