Python Basics: Operators, Expressions and Control Flow Flashcards
What do computers do?
- They perform calculations
- -> that are built into the computer’s language
- -> That you as the programmer define - Remembers results
- Computers only do what you tell them
What is declarative knowledge?
A statement of facts.
i.e. A student must pass 3 out of 5 mandatory assignments to qualify for the exam
What is imperative knowledge?
“How to…“/Recipe:
- Sequence of simple steps
- Flow of control process that specifies when each step is executed
- information when to stop
i. e.
1. A student takes a mandatory assignment and works on it
2. He uploads the solution before the deadline
3. Teacher will grade and let them know if they passed or failed
4. Repeat the above procedure 5 times
5. See if the student passes or fails the course
What is a fixed program computer?
A computer that will solve a specific mathematical problem but nothing else i.e. calculator
What is a stored program computer?
The computer stores and executes instructions (certain elements of the computer will execute the instructions in a specific sequence)
What are the three main parts in a basic machine architecture?
Memory
Control Unit
Arithmetic Logic Unit
What is a syntax?
The structure of statements in a computer language:
i.e. “hi” 5 not valid
but 3.2 * 5 is valid
What are semantics?
the meaniing of a syntactically correct string of symbols with no static semantic errors.
Caution: such strings only have one meaning in programming languages
What are different syntactic/semantic errors?
- Syntactic errors
- -> common and easily found (IDE shows them) - Static semantic errors
- -> some languages check for them before running a program
- -> can cause unpredicted behavior - No semantic error but different meaning than what programmer intended
- -> program crashes
- -> runs forever
- -> gives an outcome but different than what was expected
What is the difference between interpreted and compiled?
- Compiled languages are first converted into machine-readable code that the processor can execute (faster and more efficient than interpreted languages, better control over memory and CPU usage) i.e. C, C++
- Executed directly –> Interpreters run a program line by line and execute command one by one , often easier to debug as interpreter can produce error messages that are easy to set into relation with the code
i. e. Pytho, JavaScript
What is a (Python) Program?
- A program is a sequence of definitions and commands
- -> definitions are evaluated and commands executed by the python interpreter - Command statements instruct the interpreter what to do
- Programs can be directly typed into a shell or stored in a file that is read into the shell and evaluated
What are data objects?
- An instance of a data type (The type defines what the program can do with them)
- Programs manipulate data objects
- Objects are
- -> scalar (can be subdivided)
- -> non-scalar (have internal structure that can be accessed)
Name a few scalar objects?
int, float, bool, double, NoneType
What is an expression?
- Expressions combine objects and operators
- Has a value
- Syntax: object operator object
i.e. + (Sum), - (Difference), * (Product), / (Division), %(Remainder), ** (power of)
How do you bind variables and values?
Using the equal sign
pi = 3.14159