SlideShare a Scribd company logo
1 of 28
15-110: Principles of
Computing
Introduction: Computers and Programming Languages
Lecture 1, September 02, 2018
Mohammad Hammoud
Carnegie Mellon University in Qatar
Today…
• Introduction (~70 minutes):
• Motivation
• Hardware basics
• High-level vs. low-level programming languages
• Compiling vs. interpreting high-level languages
• Writing very simple Python commands using the interactive mode
• Adminstrivia (~10 minutes):
• Course overview
Computers and Programming
• A computer is just a machine (the hardware) for executing programs
(the software)
• Hence, the software rules the hardware!
• The process of creating software is called programming, and it is the
focus of this course
• Virtually, anyone can learn how to program computers
• It requires only some grit!
Why Learn Programming?
• Computers have become commonplace in our modern life
• Understanding the strengths and limitations of computers requires some
understanding of programming
• Programming can be loads of fun!
• It is an intellectually engaging activity that allows you to express yourself
through remarkably beautiful creations
• Programming develops valuable problem-solving skills, especially
ones that pertain to analysis, design and implementation
• Programmers are in great demand!
Gene
Sequencing and
Biotechnology
Smaller, Faster,
Cheaper Sensors
Astronomy
Ubiquitous
Computing
Why Learn Programming?
• Computers have become commonplace in our modern life
• Applying ideas in different fields requires programming
• Programming can be loads of fun!
• It is an intellectually engaging activity that allows you to express yourself
through remarkably beautiful constructs and structures
• Programming develops valuable problem-solving skills, especially
ones that pertain to analysis, design and implementation
• Programmers are in great demand!
Hardware Basics
• To be a successful programmer, you need to know some details of
how computers work
• For instance, understanding the basics of hardware will help you
analyze the performance (or efficiency) of any of your programs
• Will the data of your program fit in memory?
• If not, how would that impact the performance of your program?
• Is your program CPU-bound or IO-Bound?
• If CPU-bound, how powerful is your CPU?
• If IO-bound, how big is your disk or network bandwidth?
Functional View of a Computer
Input
Devices
CPU
Main
Memory
Output
Devices
Secondary
Memory
Functional View of a Computer
E.g., Hard Disk
• 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
Secondary
Memory
Functional View of a Computer
Main
Memory
Secondary
Memory
E.g., Random Access Memory (RAM)
• 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
Functional View of a Computer
CPU
Main
Memory
Secondary
Memory
• The Central Processing Unit (CPU) is the “brain” of the computer
• It can at least perform:
• Arithmetic operations
(e.g., adding 2 numbers)
• Logical operations
(e.g., test if 2 numbers
are equal)
• It can directly access
information stored in main memory but not in secondary memory
Functional View of a Computer
Input
Devices
CPU
Main
Memory
Output
Devices
Secondary
Memory
E.g., Monitor
E.g., Keyboard
and mouse
Functional View of a Computer
Input
Devices
Output
Devices
E.g., Keyboard
and mouse
E.g., Monitor
 Humans interact with computers
via Input and Output (IO) devices
 Information from Input devices
are processed by the CPU and
may be shuffled off to the main
or secondary memory
 When information need to be
displayed, the CPU sends them to
one or more Output devices
Programming Languages
• A program is just a sequence of instructions telling the computer
what to do
• Obviously, we need to provide these instructions in a language that
computers can understand
• We refer to this kind of a language as a programming language
• Python, Java, C and C++ are examples of programming languages
• Every structure in a programming language has an exact form (i.e.,
syntax) and a precise meaning (i.e., semantic)
Machine Languages
• Python, Java, C, and C++ are, indeed, examples of high-level languages
• Strictly speaking, computer hardware can only understand a very low-
level language known as machine language
• 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
Add the two numbers in the CPU
Store the result into location 2003
A Lot of
Work!
High-Level to Low-Level Languages
• In a high-level language like Python, the addition of two numbers can
be expressed more naturally:
• But, we need a way to translate the high-level language into a
machine language that a computer can execute
• To this end, high-level language can either be compiled or interpreted
c = a + b Much Easier!
Compiling a High-Level Language
• A compiler is a complex software that takes a program written in a
high-level language and translates it into an equivalent program in
the machine language of some computer
Source Code
(Program)
Compiler
Machine
Code
Running
Program
Inputs Outputs
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
• E.g., Python is an interpreted language
Source Code
(Program)
Computer
Running An
Interpreter
Inputs
Outputs
Compiling vs. Interpreting
• Compiling is a static (i.e., pre-execution), one-shot translation
• Once a program is compiled, it may be run over and over again without
further need for the compiler or the source code
• Interpreting is dynamic (i.e., happens during execution)
• The interpreter and the source code are needed every time the program runs
• Compiled programs tend to be faster, while interpreted ones lend
themselves to a more flexible programming environments (they can
be developed and run interactively)
Note on Portability
• The translation process highlights another advantage that high-level
languages have over machine languages, namely, portability
• A program for an Intel-based machine will not run on an IBM-based
machine since each computer type has its own machine language
• On the other hand, a program written in a high-level language (say, a
Python program) can be run on many different kinds of computers as
long as there is a suitable compiler or interpreter
• Python programs are said to be portable!
Writing Python Commands
• You can start the Python interpreter in an interactive mode and type
in some commands to see what happens
• When you first start the interpreter program, you may see something
like the following:
Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 19 2015, 20:38:52)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
A Python prompt indicating that the Python interpreter is waiting for you to give it a command
• Here is a sample interaction with the Python interpreter:
 print is a built-in function that
allows displaying information
on screen
 When you call the print function,
the parameters in the parentheses
tell the function what to print
 There is only 1 parameter passed to
print here, which is a textual data (or what is referred to as a string)
>>> print("Hello")
Hello
>>> print("Programming is fun!")
Programming is fun!
>>> print(3)
3
>>> print(2.3)
2.3
Writing Python Commands
>>> print("Hello")
Hello
>>> print("Programming is fun!")
Programming is fun!
>>> print(3)
3
>>> print(2.3)
2.3
• Here is a sample interaction with the Python interpreter:
Writing Python Commands
Another string parameter
An integer (int for short) parameter
A float parameter
How can we figure out in a program whether a value is an int, float, or string?
>>> type("Hello")
<class 'str'>
>>> type("Programming is fun!")
<class 'str'>
>>> type(3)
<class 'int'>
>>> type(2.3)
<class 'float'>
The Type Function
• Python provides a special function called type, which allows us to
figure out the data type of any value
Summary
• A computer is a universal information-processing machine, which can
carry out any process that can be described in sufficient detail
• A description of the sequence of steps for solving a particular
problem is called an algorithm
• Algorithms can be turned into software (programs) that determine
what the hardware (physical machine) can and does accomplish
• The process of creating software is called programming
Summary
• A basic functional view of a computer system comprises a central
processing unit (CPU), a main memory, a secondary memory, and
input and output devices
• 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)
• Computer hardware only understands a very low-level language
known as machine language
• Programs are usually written using human-oriented high-level
languages such as Python
Summary
• A high-level language must either be compiled or interpreted in order
for the computer to understand it
• High-level languages are more portable than machine languages
• Python is an interpreted language
• One way to learn about Python is to use an interactive shell for
experimentation
Next Lecture…
• Basic elements of Python programs (e.g., names, expressions, input
statements, output statements, assignment statements, etc.,)

More Related Content

Similar to Introduction to computers and programming languages

introduction computer programming languages
introduction computer programming languages introduction computer programming languages
introduction computer programming languages BakhatAli3
 
C++ programming languages lectures
C++ programming languages lectures C++ programming languages lectures
C++ programming languages lectures jabirMemon
 
Introduction to computer programming
Introduction to computer programming Introduction to computer programming
Introduction to computer programming VanessaBuensalida
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem SolvingSukhendra Singh
 
ProgFund_Lecture_1_Introduction_to_Programming.pdf
ProgFund_Lecture_1_Introduction_to_Programming.pdfProgFund_Lecture_1_Introduction_to_Programming.pdf
ProgFund_Lecture_1_Introduction_to_Programming.pdflailoesakhan
 
Week 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfWeek 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfAnonymousQ3EMYoWNS
 
Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptxPmarkNorcio
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterHossam Hassan
 
introductiontocomputerprogramming-140713205433-phpapp02.pptx
introductiontocomputerprogramming-140713205433-phpapp02.pptxintroductiontocomputerprogramming-140713205433-phpapp02.pptx
introductiontocomputerprogramming-140713205433-phpapp02.pptxummeafruz
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FITRaj vardhan
 
Computer and Programming
Computer and Programming Computer and Programming
Computer and Programming Mahsa Ch
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptxchouguleamruta24
 

Similar to Introduction to computers and programming languages (20)

introduction computer programming languages
introduction computer programming languages introduction computer programming languages
introduction computer programming languages
 
Program Logic and Design
Program Logic and DesignProgram Logic and Design
Program Logic and Design
 
C++ programming languages lectures
C++ programming languages lectures C++ programming languages lectures
C++ programming languages lectures
 
sege.pdf
sege.pdfsege.pdf
sege.pdf
 
Introduction to computer programming
Introduction to computer programming Introduction to computer programming
Introduction to computer programming
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
programming.pptx
programming.pptxprogramming.pptx
programming.pptx
 
ProgFund_Lecture_1_Introduction_to_Programming.pdf
ProgFund_Lecture_1_Introduction_to_Programming.pdfProgFund_Lecture_1_Introduction_to_Programming.pdf
ProgFund_Lecture_1_Introduction_to_Programming.pdf
 
Week 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfWeek 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdf
 
SYSTEM SOFTWARE
SYSTEM SOFTWARE SYSTEM SOFTWARE
SYSTEM SOFTWARE
 
Ic lecture8
Ic lecture8 Ic lecture8
Ic lecture8
 
Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptx
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals master
 
introductiontocomputerprogramming-140713205433-phpapp02.pptx
introductiontocomputerprogramming-140713205433-phpapp02.pptxintroductiontocomputerprogramming-140713205433-phpapp02.pptx
introductiontocomputerprogramming-140713205433-phpapp02.pptx
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FIT
 
Computer and Programming
Computer and Programming Computer and Programming
Computer and Programming
 
a1.pptx.pdf
a1.pptx.pdfa1.pptx.pdf
a1.pptx.pdf
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptx
 

Recently uploaded

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 

Recently uploaded (20)

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 

Introduction to computers and programming languages

  • 1. 15-110: Principles of Computing Introduction: Computers and Programming Languages Lecture 1, September 02, 2018 Mohammad Hammoud Carnegie Mellon University in Qatar
  • 2. Today… • Introduction (~70 minutes): • Motivation • Hardware basics • High-level vs. low-level programming languages • Compiling vs. interpreting high-level languages • Writing very simple Python commands using the interactive mode • Adminstrivia (~10 minutes): • Course overview
  • 3. Computers and Programming • A computer is just a machine (the hardware) for executing programs (the software) • Hence, the software rules the hardware! • The process of creating software is called programming, and it is the focus of this course • Virtually, anyone can learn how to program computers • It requires only some grit!
  • 4. Why Learn Programming? • Computers have become commonplace in our modern life • Understanding the strengths and limitations of computers requires some understanding of programming • Programming can be loads of fun! • It is an intellectually engaging activity that allows you to express yourself through remarkably beautiful creations • Programming develops valuable problem-solving skills, especially ones that pertain to analysis, design and implementation • Programmers are in great demand! Gene Sequencing and Biotechnology Smaller, Faster, Cheaper Sensors Astronomy Ubiquitous Computing
  • 5. Why Learn Programming? • Computers have become commonplace in our modern life • Applying ideas in different fields requires programming • Programming can be loads of fun! • It is an intellectually engaging activity that allows you to express yourself through remarkably beautiful constructs and structures • Programming develops valuable problem-solving skills, especially ones that pertain to analysis, design and implementation • Programmers are in great demand!
  • 6. Hardware Basics • To be a successful programmer, you need to know some details of how computers work • For instance, understanding the basics of hardware will help you analyze the performance (or efficiency) of any of your programs • Will the data of your program fit in memory? • If not, how would that impact the performance of your program? • Is your program CPU-bound or IO-Bound? • If CPU-bound, how powerful is your CPU? • If IO-bound, how big is your disk or network bandwidth?
  • 7. Functional View of a Computer Input Devices CPU Main Memory Output Devices Secondary Memory
  • 8. Functional View of a Computer E.g., Hard Disk • 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 Secondary Memory
  • 9. Functional View of a Computer Main Memory Secondary Memory E.g., Random Access Memory (RAM) • 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
  • 10. Functional View of a Computer CPU Main Memory Secondary Memory • The Central Processing Unit (CPU) is the “brain” of the computer • It can at least perform: • Arithmetic operations (e.g., adding 2 numbers) • Logical operations (e.g., test if 2 numbers are equal) • It can directly access information stored in main memory but not in secondary memory
  • 11. Functional View of a Computer Input Devices CPU Main Memory Output Devices Secondary Memory E.g., Monitor E.g., Keyboard and mouse
  • 12. Functional View of a Computer Input Devices Output Devices E.g., Keyboard and mouse E.g., Monitor  Humans interact with computers via Input and Output (IO) devices  Information from Input devices are processed by the CPU and may be shuffled off to the main or secondary memory  When information need to be displayed, the CPU sends them to one or more Output devices
  • 13. Programming Languages • A program is just a sequence of instructions telling the computer what to do • Obviously, we need to provide these instructions in a language that computers can understand • We refer to this kind of a language as a programming language • Python, Java, C and C++ are examples of programming languages • Every structure in a programming language has an exact form (i.e., syntax) and a precise meaning (i.e., semantic)
  • 14. Machine Languages • Python, Java, C, and C++ are, indeed, examples of high-level languages • Strictly speaking, computer hardware can only understand a very low- level language known as machine language • 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 Add the two numbers in the CPU Store the result into location 2003 A Lot of Work!
  • 15. High-Level to Low-Level Languages • In a high-level language like Python, the addition of two numbers can be expressed more naturally: • But, we need a way to translate the high-level language into a machine language that a computer can execute • To this end, high-level language can either be compiled or interpreted c = a + b Much Easier!
  • 16. Compiling a High-Level Language • A compiler is a complex software that takes a program written in a high-level language and translates it into an equivalent program in the machine language of some computer Source Code (Program) Compiler Machine Code Running Program Inputs Outputs
  • 17. 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 • E.g., Python is an interpreted language Source Code (Program) Computer Running An Interpreter Inputs Outputs
  • 18. Compiling vs. Interpreting • Compiling is a static (i.e., pre-execution), one-shot translation • Once a program is compiled, it may be run over and over again without further need for the compiler or the source code • Interpreting is dynamic (i.e., happens during execution) • The interpreter and the source code are needed every time the program runs • Compiled programs tend to be faster, while interpreted ones lend themselves to a more flexible programming environments (they can be developed and run interactively)
  • 19. Note on Portability • The translation process highlights another advantage that high-level languages have over machine languages, namely, portability • A program for an Intel-based machine will not run on an IBM-based machine since each computer type has its own machine language • On the other hand, a program written in a high-level language (say, a Python program) can be run on many different kinds of computers as long as there is a suitable compiler or interpreter • Python programs are said to be portable!
  • 20. Writing Python Commands • You can start the Python interpreter in an interactive mode and type in some commands to see what happens • When you first start the interpreter program, you may see something like the following: Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 19 2015, 20:38:52) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> A Python prompt indicating that the Python interpreter is waiting for you to give it a command
  • 21. • Here is a sample interaction with the Python interpreter:  print is a built-in function that allows displaying information on screen  When you call the print function, the parameters in the parentheses tell the function what to print  There is only 1 parameter passed to print here, which is a textual data (or what is referred to as a string) >>> print("Hello") Hello >>> print("Programming is fun!") Programming is fun! >>> print(3) 3 >>> print(2.3) 2.3 Writing Python Commands
  • 22. >>> print("Hello") Hello >>> print("Programming is fun!") Programming is fun! >>> print(3) 3 >>> print(2.3) 2.3 • Here is a sample interaction with the Python interpreter: Writing Python Commands Another string parameter An integer (int for short) parameter A float parameter How can we figure out in a program whether a value is an int, float, or string?
  • 23. >>> type("Hello") <class 'str'> >>> type("Programming is fun!") <class 'str'> >>> type(3) <class 'int'> >>> type(2.3) <class 'float'> The Type Function • Python provides a special function called type, which allows us to figure out the data type of any value
  • 24. Summary • A computer is a universal information-processing machine, which can carry out any process that can be described in sufficient detail • A description of the sequence of steps for solving a particular problem is called an algorithm • Algorithms can be turned into software (programs) that determine what the hardware (physical machine) can and does accomplish • The process of creating software is called programming
  • 25. Summary • A basic functional view of a computer system comprises a central processing unit (CPU), a main memory, a secondary memory, and input and output devices • 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)
  • 26. 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) • Computer hardware only understands a very low-level language known as machine language • Programs are usually written using human-oriented high-level languages such as Python
  • 27. Summary • A high-level language must either be compiled or interpreted in order for the computer to understand it • High-level languages are more portable than machine languages • Python is an interpreted language • One way to learn about Python is to use an interactive shell for experimentation
  • 28. Next Lecture… • Basic elements of Python programs (e.g., names, expressions, input statements, output statements, assignment statements, etc.,)