Python Programming: An Introduction to Computer ScienceObjectivesObjectives (cont.)The Universal MachineSlide 5Slide 6Program PowerSlide 8What is Computer Science?Slide 10Slide 11Slide 12Hardware BasicsSlide 14Slide 15Slide 16Programming LanguagesSlide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24The Magic of PythonSlide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Inside a Python ProgramSlide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Chaos and ComputersSlide 45Slide 46Python Programming, 2/e 1Python Programming:An Introduction toComputer ScienceChapter 1Computers and ProgramsObjectivesTo understand the respective roles of hardware and software in a computing system.To learn what computer scientists study and the techniques that they use.To understand the basic design of a modern computer.2Python Programming, 2/eObjectives (cont.)To understand the form and function of computer programming languages.To begin using the Python programming language.To learn about chaotic models and their implications for computing.3Python Programming, 2/eThe Universal MachineA modern computer can be defined as “a machine that stores and manipulates information under the control of a changeable program.”Two key elements:Computers are devices for manipulating information.Computers operate under the control of a changeable program.4Python Programming, 2/eThe Universal MachineWhat is a computer program?A detailed, step-by-step set of instructions telling a computer what to do.If we change the program, the computer performs a different set of actions or a different task.The machine stays the same, but the program changes!5Python Programming, 2/eThe Universal MachinePrograms are executed, or carried out.All computers have the same power, with suitable programming, i.e. each computer can do the things any other computer can do.6Python Programming, 2/eProgram PowerSoftware (programs) rule the hardware (the physical machine).The process of creating this software is called programming.Why learn to program?Fundamental part of computer scienceHaving an understanding of programming helps you have an understanding of the strengths and limitations of computers.7Python Programming, 2/eProgram PowerHelps you become a more intelligent user of computersIt can be fun!Form of expressionHelps the development of problem solving skills, especially in analyzing complex systems by reducing them to interactions between simpler systems.Programmers are in great demand!8Python Programming, 2/eWhat is Computer Science?It is not the study of computers!“Computers are to computer science what telescopes are to astronomy.” –E. DijkstraThe question becomes, “What processes can be described?”This question is really, “What can be computed?”9Python Programming, 2/eWhat is Computer Science?DesignOne way to show a particular problem can be solved is to actually design a solution.This is done by developing an algorithm, a step-by-step process for achieving the desired result.One problem – it can only answer in the positive. You can’t prove a negative!10Python Programming, 2/eWhat is Computer Science?AnalysisAnalysis is the process of examining algorithms and problems mathematically.Some seemingly simple problems are not solvable by any algorithm. These problems are said to be unsolvable.Problems can be intractable if they would take too long or take too much memory to be of practical value.11Python Programming, 2/eWhat is Computer Science?ExperimentationSome problems are too complex for analysis.Implement a system and then study its behavior.12Python Programming, 2/eHardware BasicsThe 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.13Python Programming, 2/eHardware BasicsMemory 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)14Python Programming, 2/eHardware BasicsInput devicesInformation is passed to the computer through keyboards, mice, etc.Output devicesProcessed information is presented to the user through the monitor, printer, etc.15Python Programming, 2/eHardware BasicsFetch-Execute CycleFirst instruction retrieved from memoryDecode the instruction to see what it representsAppropriate action carried out.Next instruction fetched, decoded, and executed.Lather, rinse, repeat!16Python Programming, 2/eProgramming LanguagesNatural language has ambiguity and imprecision problems when used to describe complex algorithms.Programs expressed in an unambiguous , precise way using programming languages.Every structure in programming language has a precise form, called its syntaxEvery structure in programming language has a precise meaning, called its semantics.17Python Programming, 2/eProgramming LanguagesProgramming 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.18Python Programming, 2/eProgramming LanguagesHigh-level computer languagesDesigned to be used and understood by humansLow-level languageComputer hardware can only understand a very low level language known as machine language19Python Programming, 2/eProgramming LanguagesAdd two numbers:Load the number from memory location 2001 into the CPULoad the number from memory location 2002 into the CPUAdd the two numbers in the CPUStore the result into location 2003In reality, these low-level instructions are represented in binary (1’s and 0’s)20Python Programming, 2/eProgramming LanguagesHigh-level languagec = a + bThis needs to be translated into machine language that the computer can execute.Compilers convert programs written in a high-level language into the machine language of some computer.21Python Programming, 2/eProgramming LanguagesInterpreters simulate a computer that understands a high-level language.The
View Full Document