Python Chapter 1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Storing Characters

- All data stored in computer must be stored in binary - Characters are converted to numeric code, stored in memory - ASCII - Unicode

General categories of software

- Application software - System software

Storing numbers

- Bit represents two values, 0 and 1 - Computers use binary numbering system (base 2) - Position of digit j is assigned the value 2j-1 - To determine value of binary number sum position values of the 1s - Byte size limits are 0 and 255 - 0 = all bits off; 255 = all bits on - To store larger number, use several bytes

Random Access Memory (RAM)

- CPU is able to quickly access data in RAM - Volatile memory used for temporary storage while program is running - Volatile memory: Contents are erased when computer is off - Ram is close to the CPU physically so the CPU can access data fast

Secondary Storage Devices

- Can hold data for long periods of time - Programs normally stored here and loaded to main memory when needed - Non-volatile: When you turn the power off, the information is still there - Example: Hard drive or a flash drive; when we want to run it, it has to be copied into RAM

Typical major components of Hardware

- Central processing unit - Main memory - Secondary storage devices - Input and output devices

Output

- Data produced by the computer for other people or devices - Can be text, image, audio, or bit stream

Types of secondary memory

- Disk drive - Solid state drive - Flash memory - Optical devices

CPU Executes programs in cycle:

- Fetch: read the next instruction from memory into CPU (OS fetches instruction from RAM and load it into the CPU) - Decode: CPU decodes fetched instruction to determine which operation to perform (figures out what the instruction was saying (add, multiply, &)) - Execute: perform the operation

Output device

- Formats and presents output - Examples: video display, printer - Disk drives and USB drives can be considered output devices because data is sent to them to be saved

ASCII

- Most important coding scheme is ASCII - ASCII is limited: defines codes for only 128 characters (8 bits)

Programmer

- Person who can design, create, and test computer programs - Also known as software developer

Application software

- Programs that make computer useful for every day tasks - What people normally spend most of their time running on their computer - Examples: word processing, email, games, and Web browsers - Also: spreadsheet programs, Powerpoint In this course we are writing application software

Program

- Set of instructions that a computer follows to perform a task - Commonly referred to as Software

IDLE (Integrated Development Program)

- Single program that provides tools to write, execute and test a program - Automatically installed when Python language is installed - Runs in interactive mode and script mode - Has built-in text editor with features designed to help write Python programs

Source code

- Statements written by programmer - Syntax error: a mistake such as a misspelled key word, a missing punctuation character, or the incorrect use of an operator. This prevents code from being translated

Central Processing Unit (CPU)

- The part of the computer that actually runs programs - Most important component - Without it, cannot run software - Used to be a huge device - CPU does arithmetic and it does logic - Where the instructions get executed - Used to be really big but now they use microprocessors

Hardware

- The physical devices that make up a computer - Computer is a system composed of several components that all work together - Anything that can be programmed as software - Can be built into hardware - Ex: anti lock breaks

Advanced numbers storage

- To store negative numbers and real numbers, computers use binary numbering and encoding schemes - Negative numbers encoded using two's complement notation - Real numbers encoded using floating-point notation - These are more advanced topics, typically not in this course

Interpreter

- Translates and executes instructions in high-level language program - Used by Python language - Interprets one instruction at a time - No separate machine language program

Unicode

- Unicode coding scheme becoming standard - Compatible with ASCII (but 16 bits) - Can represent characters for other languages

Basic von Neumann Model

1940s (still in effect!!!) Llnl is Lawrence Livermore National Lab Logic Operations: true of false - Ex: it is raining and it is warm - This is false because it is not raining - If they are both true then it is true, but if one or more is false then the whole thing is false - Memory is just storage

Natural language

Add 5 and 6, and store the result in "sum" - While we may someday write programs in a natural language, not possible yet - Natural languages are extremely complex compared to programming languages in use today

How computers store data

All data in a computer is stored in sequences of 0s and 1s

High level language (pt 2)

Allows simple creation of powerful and complex programs - No need to know much about how CPU works or write large number of instructions - More intuitive to understand

High level languages

C, C++, C#, Pascal, Basic, JAVA, Fortran, COBOL, Python, Ada; there are MANY! sum = 5 + 6 # this is Python code - Instructions closer to natural language - Easier to read, write, debug & modify - Built-in data types, control structures & data structures (which we will study this term) - Much more portable across platforms

How a program works

CPU designed to perform simple operations on pieces of data - Examples: reading data, adding, subtracting, multiplying, and dividing numbers - "Understands" instructions written in machine language and included in its instruction set - Each brand of CPU has its own ISA (instruction set architecture) - Machine language is BINARY To carry out meaningful calculation, CPU must perform many operations - Program must be copied from secondary memory to RAM each time CPU executes it - CPU executes program in cycle

Microprocessors

CPUs located on small chips

Python interpreter

Can be used in 2 modes: - Interactive mode: enter statements on keyboard one at a time - Script mode: save statements in Python script

Low level language

Close in nature to machine language Example: assembly language

Input Device

Component that collects the data - Examples: keyboard, mouse, touchscreen, scanner, camera - Disk drives can be considered input devices because they load programs into the main memory

Operating system

Controls operations of hardware components (e.g. Windows, Mac OS, UNIX)

Optical Devices

Data encoded optically - CD, DVD - Common for creating backup copies of data

Input

Data the computer collects from people and other devices

Other types of data

Digital: describes any device that stores data as binary numbers Digital images are composed of pixels - To store images, each pixel is converted to a binary number representing the pixel's color (PIXEL: stands for 'picture element') Digital music is composed of sections called samples - To store music, each sample is converted to a binary number True/False - True: 00000001 - False: 00000000

Bit

Electrical component that can hold positive or negative charge, like on/off switch, or pass high or low voltage, etc. - The on/off pattern of bits in a byte represents data stored in the byte

Software

Everything the computer does is controlled by software

Solid State Drive

Faster than disk drive, no moving parts, stores data in solid state memory

From machine language to assembly language

Impractical for most people to write in machine language, though many do - Assembly language: uses short words (mnemonics) for instructions instead of binary numbers - Easier for programmers to work with - Assembler: translates assembly language to machine language for execution by CPU

Statement

Individual instruction used in high-level language ( e.g. print ( 5 + 6 ) )

Machine language

Instructions in binary code, which computer "understands"; set of all these instructions comprise a computer's Instruction Set Architecture (ISA) - Direct control of machine - Difficult to program, read, debug - Not portable to other platforms

Byte

Just enough memory to store letter or small number - Divided into eight bits - Think of a byte as 8 switches

Disk Drive

Magnetically encodes data onto a spinning circular disk - Most common type

Types of system software

Operating system Utility Program Software development tools

Operators

Perform operations on data Example: math operators to perform arithmetic ( e.g. + )

Utility Program

Performs specific task to enhance computer operation or safeguard data (e.g. anti-virus)

Flash memory

Portable, no physical disk

Key words

Predefined words used to write program in high-level language Each key word has specific meaning (e.g. if)

System software

Programs that control and manage basic operations of a computer

Using Python

Python must be installed and configured prior to use - One of the items installed is the Python interpreter

Syntax

Set of rules to be followed when writing program

Writing Python Programs and Running Them in Script Mode

Statements entered in interactive mode are not saved as a program To store a program use script mode - Save a set of Python statements in a file - The filename should have the .py extension - To run the file, or script, type python filename at the operating system command line

Compiler

Translates high-level language program into separate machine language program - Machine language program can be executed at any time

Software development tools

Used to create, modify, and test software programs (e.g. compilers and interpreters)

Interactive mode

When you start Python in interactive mode, you will see a prompt - Indicates the interpreter is waiting for a Python statement to be typed - Prompt reappears after previous statement is executed - Error message displayed if you incorrectly type a statement Good way to learn new parts of Python

Main Memory

Where computer stores a program while program is running, and data used by the program - Known as Random Access Memory or RAM

Programs written in _________ languages must be translated into _________ language to be executed

high-level; machine

Assembly language

load 5 # very generic example load 6 add store sum - These instructions typically correspond 1-1 with machine language instructions - Use mnemonic codes (e.g. "ld" for "load") - Symbolic names (like sum) - Direct control - Still hard to use and not portable


Set pelajaran terkait

Abeka economics quiz 10 pg. (128-135)

View Set

NUR 209 Ch. 16 Documenting, Reporting, Conferring, and Using Informatics (Fundamentals of Nursing)

View Set

Pyschology 1302 - Chapter 8 - Memory - Quiz Bank

View Set

NUR 236: Chapter 41 Sexually transmitted infections

View Set

APUSH ch 12 quiz, APUSH Ch 13 quiz, APUSH Ch 14 quiz, APUSH ch 15 quiz

View Set

Hacker Techniques Tools and Incident Handling

View Set