1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)

Slides:



Advertisements
Similar presentations
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
Advertisements

Lecture 1: Intro to Computers Yoni Fridman 6/28/01 6/28/01.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
Computer Hardware.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
CIS 260 Computer Programming I in C Prof. Timothy Arndt.
CS 0008 Day 2 1. Today Hardware and Software How computers store data How a program works Operators, types, input Print function Running the debugger.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
CS102 Introduction to Computer Programming
Introduction to Computers and Python. What is a Computer? Computer- a device capable of performing computations and making logical decisions at speeds.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
Introduction to Programming Dr Masitah Ghazali Programming Techniques I SCJ1013.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs.
Adapted from John Zelle’s Book Slides1 CS177 Python Programming Chapter 1 Computers and Programs.
Chapter 3 Computer Hard ware
CS190/295 Programming in Python for Life Sciences: Lecture 2 Instructor: Xiaohui Xie University of California, Irvine.
Topics Introduction Hardware and Software How Computers Store Data
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computer Science.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Python Programming: An Introduction to Computer Science
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs.
CISC105 General Computer Science Class 1 – 6/5/2006.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
What is a Computer? An, electrical machine, that can be programmed to accept data (input), process it into useful information (output) and store it away.
Introduction to Programming Using C Introduction to Computer Programming.
Intro to Computers Computer Apps 1.
Introduction to Computer Systems and the Java Programming Language.
CPSC- 120 Principle of Computer Science I Computer = Hardware + Software.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
COMPUTER ORGANISATION I HIGHER STILL Computing Computer Systems Higher Marr College Computing Department 2002.
Parts of the Computer System
CS 127 Introduction to Computer Science. What is a computer?  “A machine that stores and manipulates information under the control of a changeable program”
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
A.Abhari CPS1251 Topic 1: Introduction to Computers Computer Hardware Computer components Connecting Computers Computer Software Operating System (OS)
Computer Programming (1) Code & No.: CS 102 CREDIT HOURS: 5 UNIT Lecture 3.0 hours/week Lab: 2.0 hour/on every week a. This course introduces the students.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Introduction To Computers
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Python Programming, 3/e1 Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs.
Python Programming Module 1 Computers and Programs Python Programming, 2/e1.
And now for something completely different…
Chapter 1: Introduction to Computers and Programming
BASIC PROGRAMMING C SCP1103 (02)
Topics Introduction Hardware and Software How Computers Store Data
BASIC PROGRAMMING C SCP1103 (02)
Chapter 1: Introduction to Computers and Programming
CS190/295 Programming in Python for Life Sciences: Lecture 1
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Topics Introduction Hardware and Software How Computers Store Data
A primer on Computers and Programs
15-110: Principles of Computing
Computer Programming-1 CSC 111
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)

Objectives To understand the basic design of a modern computer. To understand the form and function of computer programming languages. To begin using the Python programming language.

Hardware and software: which is more important? Source: important-hardware-software/abr0137l/

0 and 1 conquer the world! Bit: binary digit Byte Binary number system Binary arithmetic (Gottfried Wilhelm von LEIBNIZ ( ))

Why only two values? Source: Charles Dierbach Introduction to Computer Science Using Python. Wiley.

The binary number system Source: Charles Dierbach Introduction to Computer Science Using Python. Wiley.

Raspberry Pi

Hardware basics

Hardware Basics The central processing unit (CPU) is the “brain” of a computer. The CPU carries out all the basic operations on the data. Examples: simple arithmetic operations, testing to see if two numbers are equal.

Hardware Basics Memory stores programs and data. CPU can only directly access information stored in main memory (RAM or Random Access Memory). Main memory is fast, but volatile, i.e. when the power is interrupted, the contents of memory are lost. Secondary memory provides more permanent storage: magnetic (hard drive, floppy), optical (CD, DVD)

The memory hierarchy Source:

Hardware Basics Input devices Information is passed to the computer through keyboards, mouse, etc. Output devices Processed information is presented to the user through the monitor, printer, etc.

Hardware Basics Fetch-Execute Cycle First instruction retrieved from memory Decode the instruction to see what it represents Appropriate action carried out. Next instruction fetched, decoded, and executed.

Programming Languages Natural language has ambiguity and imprecision problems. Programs expressed in an unambiguous, precise way using programming languages. Every structure in programming language has a precise form, called its syntax Every structure in programming language has a precise meaning, called its semantics.

Programming Languages Programming language like a code for writing the instructions the computer will follow. Programmers will often refer to their program as computer code. Process of writing an algorithm in a programming language often called coding.

Programming Languages High-level computer languages Designed to be used and understood by humans Low-level language Computer hardware can only understand a very low level language known as machine language

Source:

An example Source:

Compiling vs interpreting Compiling the source code to machine code Source:

Compiling vs interpreting Source: an-overview-of-the-differences

Compiling vs. Interpreting Once program is compiled, it can be executed over and over without the source code or compiler. If it is interpreted, the source code and interpreter are needed each time the program runs. Compiled programs generally run faster since the translation of the source code happens only once.

For Python Source:

Let’s start using Python!

EXERCISE 1.1 Open your Python IDLE Type print(“Hello, World!”). Type print(2+3). Type print(“2+3”, 2+3). Type print("2 + 3", "3+2"). Type print.

print() is a built-in function. IDLE is a program development environment for Python. The interactive environment is called a (command) shell. A complete command is a statement. A function takes in one or more parameters (or arguments) which could be Character strings (i.e., text) Number Arithmetic expression

EXERCISE 1.2 Type >>> def hello(): print("Hello") print(“CS is fun!") After entering a new line and get the prompt, type hello().

Defining a new function hello() def is a Python keyword for defining a new function. The first line tells Python we are defining a new function called hello. The following lines are indented to show that they are part of the hello function. The blank line (hit enter twice) lets Python know the definition is finished. Type the function name (including the parentheses) to invoke (or call) the function.

EXERCISE 1.3 Modify the previous hello() to hello(name) so that when hello(“Rocky”) is called, the output will be Hello, Rocky, CS is fun! (Note that all the outputs will be on the same line.)

Saving the program in a.py file. Programs are usually composed of functions, modules, or scripts that are saved on disk so that they can be used again and again. A module file is a text file created in text editing software (saved as “plain text”) that contains function definitions. We’ll use filename.py when we save our work to indicate it’s a Python program.

EXERCISE 1.4 Get a Python program called chaos.py from the course website and save it in your machine and run it with different input values to observe the “chaotic behavior.” Ref: Watch the double rod pendulum animation in

The chaos program Lines that start with # are called comments. Python skips text from # to end of line. Using main() for the function. x is an example of a variable. A variable is used to assign a name to a value so that we can refer to it later. The quoted information is displayed, and the number typed in response is stored in x. for (another Python keyword) is a loop construct A loop tells Python to repeat the same thing over and over. In this example, the code is repeated 10 times.

The math stuff x = 3.9 * x * (1 - x) is called an assignment statement. The part on the right-hand side (RHS) of the “=“ is a mathematical expression. * is used to indicate multiplication. Once the value on the RHS is computed, it is stored back into (assigned) into x.

END