Module 1 - the way of the program Flashcards
What is a program?
A set of instructions that tells a computer what to do (follows to perform a task, it specifies how to perform a computation)
Input
Data collected from input device (keyboard, network, file, hard drive)
Output
Data produced by the computer and displayed on an output device (screen, printer, save it in a file, send it over a network)
Conditional execution
Check for certain conditions and run appropriate code
What appears in almost every language?
Input/output, math, conditional execution, repetition
Python interpreter
A program that reads and executes python code
First three lines of python interpreter
Python 3.4 = version number
Operating system
Prompt (“»>” which means interpreter is ready for you to enter code)
How to display “Hello World!” in python
Print(“Hello world!”)
This is called a print statement
What do parenthesis indicate?
Function Print("Hello world") is a function
Arithmetic Operator
Special symbol in python that represents computations like addition and multiplication
What’s the arithmetic operator for exponentiation (exponents)?
**
So, 6**2 is 6^2 = 36
What does ^ mean in python?
Bitwise operator XOR
What is a value?
Basic unit of data, like a letter or number, that a program manipulates
What are the different types of values?
Integer, floating-point number, and string
If you’re not sure what the type is, how can you find out?
Ask the interpreter!
»>type(2)
(If you put ‘2’ it will show up as string)
Natural vs. formal languages
Natural languages (English, Spanish) evolved naturally and not designed by people Formal languages (Python, Math) are designed by people for specific applications, they have syntax rules, they are unambiguous, literal, concise
What is syntax? What are the two types of syntax rules?
Set of coding rules; tokens and structure
What are tokens?
Basic elements of a language, such as words, numbers, and chemical elements
For example, 3+=3$6 doesn’t work because $ is not a legal token in math
What are structure rules?
Pertains to the way tokens are combined
3+/3 is illegal in math because, although tokens are valid, you can’t have + and / next to each other
Parsing
Figuring out the structure of a language
Separating a string of commands and analyzing for correct syntax
Programming errors are called ___. What is the process of finding and correcting them called?
Bugs, debugging
Portability
Property of a program that allows it to run on more than one kind of computer
Prompt
Characters displayed by the interpreter to indicate it is ready to take input from the user (»>)
Microprocessor
CPU on a small chip
Main Memory (RAM)
Random Access Memory
Volatile (temporary)
Contents are erased when the computer is off
Secondary Storage (Hard drive)
Programs are stored here and loaded to main memory when needed
Examples include disk drive, hard drive, SSD (solid state drive - faster than disk drive), flash memory (portable)
What are the two categories of software?
Application (programs used by end user) and System (control and manage basic operations of a computer = operating system, utility - to enhance computer operation, software development tools)
How many bits in a byte?
8
What are byte size limits?
0-255
0 = all bits off
255 = all bits on
*a byte is 8 bits, so if you have 11111111 and you convert to decimal system, you get 256 (1x2^7 + 1x2^6…)
Why is RAM called that?
It is called Random, because the data stored in RAM can be accessed with the same amount of ‘Access’ time, regardless of the location.
This is as opposed to sequential memory like a tape, where items at the beginning of the tape are accessed faster than items at the middle of the tape, as we need to roll the tape to the middle to get the data stored there.
A byte in memory is identified by a unique number called its _____.
Address
The decimal equivalent of the binary numeral 10101 is ______. How to calculate?
(12^0) + ( 02^1) + (12^2) + (02^3) + (1*2^4) = 16+4+1 = 21
value* 2^(j-1) where j is the position
The rules that govern the correct order and usage of the elements of a language are called the _____ of the language.
Syntax
What is the difference between 2 and 1+1?
1+1 is called an expression. Anything that requires simplification is referred to as an expression, while 1 or 2, or “hello’ are referred to as literals. They can not be further simplified.
How do you perform integer division (i.e., no remainder) in Python?
// for example, 7//2 will be 3
Count to 10 in binary
0 1 10 11 100 101 110 111 1000 1001 1010
*even numbers always end in 0
How to convert: decimal > binary? For example, 13
Divide by 2 and write down the remainder 13/2 = 6, R1 6/2 = 3, R0 3/2 = 1, R1 1/2 = 0, R1 Your last remainder is your first number 1101
How to convert: binary > decimal? For example, 110
To convert 110 - Start w/ the last digit, 0: 0 x 2^0 = 0 x 1 = 0 1 x 2^1 = 1 x 2 = 2 1 x 2^2 = 1 x 4 = 4 Add them up! = 6
How is data stored in a computer? What is the format?
As a bit = binary digit! 0 or 1
Everything is converted to numeric code
What is ASCII? (“ask-ee”)
American Standard Code for Information Interchange
Represents 128 English Characters as numbers; each letter is assigned a number 0-127 (for example capital m (“M”) is 77)
What is unicode?
Compatible w/ ASCII - represents characters from other languages too
Digital
Any device that stores data as binary numbers
For example, digital images are composed of pixels, each pixel is converted to binary number representing that pixel’s color
What is program cycle for CPU?
Program copied from secondary memory to RAM:
- CPU fetches the instruction
- Decodes it to determine which operation to perform
- Executes the instruction
Assembler, Compiler, Interpreter
- Assembler translates assembly language to machine language for execution by CPU
- Compiler translates one language to another (usually high-level language to machine language)
- Interpreter translates AND executes line by line - not an entire separate program
Operators
Perform operations on data
For example, math operators perform arithmetic
What are the two modes of Python?
Interactive (enter statements, limited, use to test functions) and Script Mode (save statements in python script)
Literal
A value that cannot be simplified (“Hello world!”, 6, etc.)
Statement vs. expression
A statement does something (e.g., print statement)
An expression evaluates to a value (e.g., 1+2)
A statement is a complete line of code that performs an action
An expression is any combination of variables, operations, and values that yields a result value
Operation
Action involving an operator
What is a script?
Can be executed without compiler
A script or scripting language is a computer language with a series of commands within a file that is capable of being executed without being compiled (ie translated to machine language)
Compile
The process of creating an executable program from code written in a compiled programming language
Compiling allows the computer to run and understand the program without the need of the programming software used to create it
Which of these will cause an error message in Python?
- print(“hello world)
- print (“hello world”
- 2++2
- 09
- 4 5
1, 2, 4, 5. These will return syntax error:
Leaving out parentheses or quotes (for strings) in print statement
Leading 0s, as in 09 or 011
Two values with no operator between them
In a binary numbering system, what is the formula to determine value of digit j?
2^(j-1)