Fundamentals of Python: First Programs, 2e

Fundamentals of Python: First Programs, 2e

Fundamentals of Python: First Programs Second Edition Chapter 1 Introduction 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 1 Objectives 1.1 Describe the basic features of an algorithm 1.2 Explain how hardware and software collaborate in a computers architecture

1.3 Give a brief history of computing 1.4 Compose and run a simple Python program 2018 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. Two Fundamental Ideas of Computer Science: Algorithms and Information Processing Computer science focuses on a broad set of interrelated ideas Two of the most basic ones are: Algorithms Information processing 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use.

3 Algorithms (1 of 2) Steps for 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 numbers 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

Sequence of steps that describes each of these computational processes is called an algorithm 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 4 Algorithms (2 of 2) Features of an algorithm: Consists of a finite number of instructions Each individual instruction is well defined - Action described by the instruction can be performed effectively or be executed by a computing agent

Describes a process that eventually halts after arriving at a solution to a problem Solves a general class of problems Computers can be designed to run a small set of algorithms for performing specialized tasks 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 5 Information Processing Information is also commonly referred to as data In carrying out the instructions of an algorithm, computing agent manipulates information

Starts with input Transforms information according to well-defined rules Produces output The algorithms that describe information processing can also be represented as information Computer scientists recently discovered how to represent many other things, such as: Images, music, human speech, and video 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 6

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 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 7 Computer Hardware (1 of 3) Basic hardware components of a computer are: Memory Central processing unit (CPU)

Set of input/output devices Computers can also communicate with the external world through various ports that connect them to networks and to other devices 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 8 Computer Hardware (2 of 3) Computer memory is set up to represent and store information in electronic form Stored as patterns of binary digits (1s and 0s)

Random access memory (R AM) is also called internal or primary Part of a computer responsible for processing data is the central processing unit (CPU), also called processor External or secondary memory can be magnetic, semiconductor, or optical 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 9 Computer Hardware (3 of 3) 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use.

10 Computer Software (1 of 3) 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 computers operating system Some important parts: file system, user interfaces (terminal-based, GUIs, or touchscreen interface) Applications include Web browsers, word processors, spreadsheets, database managers, graphic design packages, games, etc

2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 11 Computer Software (2 of 3) Scientists have developed high-level programming languages for expressing algorithms Resemble English and allow the author to express algorithms in a form that other people can understand Programmers usually start by writing high-level language statements in a text editor Runs another program called a translator to convert program code into executable code

Translator checks for syntax errors If no errors are found, program can be executed by the run-time system Might execute program directly on the hardware or run another program called an interpreter or virtual machine to execute the program 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 12 Computer Software (3 of 3) 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use.

13 A Not-So-Brief History of Computing Systems 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 14 Before Electronic Digital Computers (1 of 4) Algorithm comes from Muhammad ibn Musa Al-Khawarizmi, a Persian mathematician Euclid developed an algorithm for computing the greatest common divisor of two numbers

The abacus also appeared in ancient times Blaise Pascal (16231662): built one of the first mechanical devices to automate addition Wilhelm Leibniz (1646-1716): built another calculator that included other arithmetic functions such as multiplication Joseph Jacquard (17521834): designed and constructed a machine that automated weaving 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 15 Before Electronic Digital Computers (2 of 4)

2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 16 Before Electronic Digital Computers (3 of 4) 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 17 Before Electronic Digital Computers (4 of 4) Charles Babbage (17921871): conceived Analytical Engine Herman Hollerith (18601929): developed a machine that automated data

processing for the U.S. Census One of the founders of company that became I BM George Boole (18151864): developed Boolean logic Alan Turing (19121954): explored the theoretical foundations and limits of algorithms and computation 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 18 The First Electronic Digital Computers (1940-1950) Late 1930s: Claude Shannon wrote paper titled A Symbolic Analysis of Relay

and Switching Circuits 1940s: Mark I (electromechanical) ENIAC (Electronic Numerical Integrator and Calculator) ABC (Atanasoff-Berry Computer) Colossus by a group working under Alan Turing John von Neumann: first memory-stored programs Mainframe computers consisted of vacuum tubes, wires, and plugs, and filled

entire rooms 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 19 The First Programming Languages (1950-1965) The first assembly languages had operations like ADD and OUTPUT Programmers entered mnemonic codes for operations at keypunch machine Card readertranslated holes in cards to patterns in computers memory Assemblertranslated application programs in memory to machine code Compiler translated programs to machine code High-level programming languages: FORTRAN, LISP, COBOL common feature: abstraction

2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 20 Integrated Circuits, Interaction, and Timesharing (1965-1975) Late 1950s: vacuum tube gave way to transistor Transistor is solid-state device Early 1960s: integrated circuit enabled smaller, faster, less expensive hardware components Moores Law: processing speed and storage capacity of HW will increase and cost will decrease by approximately a factor of 2 every 18 months

Minicomputers appeared Processing evolved from: Batch processing Time-sharing Concurrent processing 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 21 Personal Computing and Networks (1975-1990) Late 1960s: Douglas Engelbart First pointing device (mouse) and software to represent windows, icons, and pulldown menus on a bit-mapped display screen

Member of team that developed Alto (Xerox PARC) 1975: Altair, first mass-produced personal computer With Intels 8080 processor, first microcomputer chip Early 1980s: Gates and Allen build MS-D OS Bob Metcalfe created Ethernet, used in LANs ARPANET grew into what we call Internet 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 22 Consultation, Communication, and

E-Commerce (1990-2000) (1 of 2) Optical storage media was developed for mass storage Virtual reality: capacity to create lifelike 3-D animations of whole-environments Berners-Lee at CERN created W WW Based on concepts of hypermedia HTTP: Hypertext Transfer Protocol HTML: Hypertext Markup Language Components of WWW: Web servers Web browsers Web clients 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use.

23 Consultation, Communication, and E-Commerce (1990-2000) (2 of 2) Web applications presented a revolution in the way software services were delivered to people Made online stores pervasive Web application providing the service ran on a remote computer or server Client/server applications such as e-mail, bulletin boards, and chat rooms Were already in use Simply deployed on the Web when it became available Sergey Brin and Larry Page

Developed algorithms for indexing and searching the Web 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 24 Mobile Applications and Ubiquitous Computing (2000-present) Personal digital assistants (PDAs) first handheld computing devices Limited to video games, address books, to-do lists, and note taking Steve Jobs (Apple) created several key devices iPod iPhone

iPad Social networking applications major addition to the digital landscape Big data a technology where governments, businesses, and hackers continually monitor Internet traffic Researchers have created algorithms that process massive amounts of data to discover trends and predict outcomes 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 25 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 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 26 Running Code in the Interactive Shell (1 of 2) 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 I DLE

To quit, select the windows close box or press Control+D Shell is useful for: - Experimenting with short expressions or statements - Consulting the documentation 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 27 Running Code in the Interactive Shell (2 of 2) 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use.

28 Input, Processing, and Output (1 of 5) 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 In Python, inputs are Python expressions or statements Outputs are the results displayed in the shell Programmers can also force output of a value by using the print function print () Example: >>>print (Hi there)

Hi there 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 29 Input, Processing, and Output (2 of 5) The following example receives an input string from the user and saves it for further processing: >>> name = input(Enter your name:) Enter your name: Ken Lambert >>> name Ken Lambert >>> print(name)

Ken Lambert >>> 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 30 Input, Processing, and Output (3 of 5) The input function always builds a string from the users keystrokes and returns it to the program Strings that represent numbers must be converted from strings to appropriate number types Two type conversion functions: int (for integers) and float (for floating-point numbers)

2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 31 Input, Processing, and Output (4 of 5) The next session inputs two integers and displays their sum: >>> first = int(input(Enter the first number: )) Enter the first number: 23 >>> second = int(input(Enter the second number:)) Enter the second number: 44 >>> print(The sum is, first + second) The sum is 67 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license

distributed with a certain product or service or otherwise on a password-protected website for classroom use. 32 Input, Processing, and Output (5 of 5) Function What It Does float() Converts a string of digits to a floating-point value.

int() Converts a string of digits to an integer value. input() Displays the string prompt and waits for keyboard input. Returns the string of characters entered by the user. print(, ...,) Evaluates the expressions and displays them, separated by one space, in the console window.

+ Glues the two strings together and returns the result. 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 33 Editing, Saving, and Running a Script (1 of 3) We can then run Python program files or scripts within IDLE or from the OSs command prompt Run within IDLE using menu option, F5 (Windows), or Control+F5 (Mac or Linux)

Python program files use .py extension Running a script from IDLE allows you to construct some complex programs, test them, and save them in program libraries to reuse or share with others 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 34 Editing, Saving, and Running a Script (2 of 3) 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use.

35 Editing, Saving, and Running a Script (3 of 3) 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 36 Behind the Scenes: How Python Works 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 37

Detecting and Correcting Syntax Errors (1 of 2) Programmers inevitably make typographical errors when editing programs, called syntax errors The Python interpreter will usually detect these Syntax: rules for forming sentences in a language When Python encounters a syntax error in a program, it halts execution with an error message Example: >>> length = int(input(Enter the length: )) Enter the length: 44 >>> print(lenth) Traceback (most recent call last): File , line 1, in

NameError: name lenth is not defined 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 38 Detecting and Correcting Syntax Errors (2 of 2) The next statement attempts to print the value of the correctly spelled variable: >>> print(length) SyntaxError: unexpected indent Final example, programmer attempts to add two numbers, but forgets to include the second one: >>> 3 + SyntaxError: invalid syntax

2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 39 Chapter Summary (1 of 3) Fundamental ideas of computer science The algorithm Information processing Real computing agents can be constructed out of hardware devices CPU, memory, and input and output devices Some real computers are specialized for a small set of tasks, whereas a desktop

or laptop computer is a general-purpose problem-solving machine Software provides the means whereby different algorithms can be run on a general-purpose hardware device Written in programming languages 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 40 Chapter Summary (2 of 3) Languages such as Python are high-level Interpreter translates a Python program to a lower-level form that can be executed on a real computer Python shell provides a command prompt for evaluating and viewing the results

of Python expressions and statements IDLE is an integrated development environment that allows the programmer to save programs in files and load them into a shell for testing Python scripts are programs that are saved in files and run from a terminal command prompt 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 41 Chapter Summary (3 of 3) When a Python program is executed, it is translated into byte code Sent to PVM for further interpretation and execution

Syntax: set of rules for forming correct expressions and statements in a programming language 2018 Cengage. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom use. 42

Recently Viewed Presentations

  • Chapter 7 Body Systems

    Chapter 7 Body Systems

    An electric apparatus used to increase the heart rate in severe bradycardia by electrically stimulating the heart muscle . ... Biliary Drainage and Stenting: use of a stent (small mesh tube) to open up blocked ducts and allow bile to...
  • The Metric System of Measurement

    The Metric System of Measurement

    The Metric System of Measurement *Information The metric system of measurement is based on the number "ten" (10). We, the United States, use the English system which is not based on much of anything except history which is not very...
  • PEO/SYSCOM Conference Implementing Technical Performance Measurement Mike Ferraro

    PEO/SYSCOM Conference Implementing Technical Performance Measurement Mike Ferraro

    PEO/SYSCOM Conference Implementing Technical Performance Measurement Mike Ferraro General Engineer [email protected] 20-22 Nov 2002 Outline What the Literature Says Technical Performance Measurement Concept/Definitions Discussion Pilot Program Key Elements Technology Readiness Levels What's Next Summary The Question Can you plan with...
  • Employability: Professional Career Start Strategies & Job Search

    Employability: Professional Career Start Strategies & Job Search

    JOB SEARCH STRATEGIES . Employability: Professional Career Start Strategies & Job Search. Katrina Sardellis. 25 November 2015. Save this template as a new PowerPoint Presentation, giving it the name you require OR copy these templates from Slide Master view into...
  • Measuring with Metric Units Length (m) meter Volume

    Measuring with Metric Units Length (m) meter Volume

    * Note the "standard" metric system is called MKS. meters, kilograms, seconds. ... (1 cc) cc stands for cubic centimeters. 1 gallon of milk has about twice the volume of a 2-L bottle of soda. 1 gal = 3.79 L....
  • Forensic Science T. Trimpe 2006 http://sciencespot.net Fingerprint Principles

    Forensic Science T. Trimpe 2006 http://sciencespot.net Fingerprint Principles

    Forensic Science T. Trimpe 2006 http://sciencespot.net
  • Glory Forsaken

    Glory Forsaken

    Glory Forsaken. Jesus longs for the glory he once had - the glory he had forsaken. And now, Father, glorify me in your own presence with the glory that I had with you before the world existed. John 17:5
  • Agriculture & Merchants and Trade By Wezley,Bronson,Bianca,Furkan and

    Agriculture & Merchants and Trade By Wezley,Bronson,Bianca,Furkan and

    By Wezley,Bronson,Bianca,Furkan and Samantha. Ancient Egypt . Agriculture. Behind these kings and queens were pawns, behind these temples, palaces and pyramids were the workers of the cities and the peasants of the fields of Ancient Egypt Agriculture. ... They grew...