Python Basics: Operators, Expressions and Control Flow Flashcards

1
Q

What do computers do?

A
  1. They perform calculations
    - -> that are built into the computer’s language
    - -> That you as the programmer define
  2. Remembers results
  3. Computers only do what you tell them
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is declarative knowledge?

A

A statement of facts.

i.e. A student must pass 3 out of 5 mandatory assignments to qualify for the exam

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is imperative knowledge?

A

“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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a fixed program computer?

A

A computer that will solve a specific mathematical problem but nothing else i.e. calculator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a stored program computer?

A

The computer stores and executes instructions (certain elements of the computer will execute the instructions in a specific sequence)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the three main parts in a basic machine architecture?

A

Memory
Control Unit
Arithmetic Logic Unit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a syntax?

A

The structure of statements in a computer language:
i.e. “hi” 5 not valid
but 3.2 * 5 is valid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are semantics?

A

the meaniing of a syntactically correct string of symbols with no static semantic errors.

Caution: such strings only have one meaning in programming languages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are different syntactic/semantic errors?

A
  1. Syntactic errors
    - -> common and easily found (IDE shows them)
  2. Static semantic errors
    - -> some languages check for them before running a program
    - -> can cause unpredicted behavior
  3. No semantic error but different meaning than what programmer intended
    - -> program crashes
    - -> runs forever
    - -> gives an outcome but different than what was expected
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between interpreted and compiled?

A
  1. 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++
  2. 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a (Python) Program?

A
  1. A program is a sequence of definitions and commands
    - -> definitions are evaluated and commands executed by the python interpreter
  2. Command statements instruct the interpreter what to do
  3. Programs can be directly typed into a shell or stored in a file that is read into the shell and evaluated
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are data objects?

A
  1. An instance of a data type (The type defines what the program can do with them)
  2. Programs manipulate data objects
  3. Objects are
    - -> scalar (can be subdivided)
    - -> non-scalar (have internal structure that can be accessed)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Name a few scalar objects?

A

int, float, bool, double, NoneType

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is an expression?

A
  1. Expressions combine objects and operators
  2. Has a value
  3. Syntax: object operator object

i.e. + (Sum), - (Difference), * (Product), / (Division), %(Remainder), ** (power of)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you bind variables and values?

A

Using the equal sign

pi = 3.14159

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why do you give names to values of expressions?

A

To reuse the names instead of computing the values every time you need them
i.e. pi = 3.14159
radius = 2.2
area = pi * (radius ** 2)

17
Q

What happens if you change bindings?

A
  1. You can rebind variable names using new assignments

2. Previous value may still be stored but you cannot access it anymore

18
Q

What is a String?

A
  1. Sequence of characters (i.e. letters, special characters, spaces, digits)
  2. enclosed in quotation marks or single quotes “”, ‘’
  3. You can concatenate strings using +: greeting = hi + “ “ + name
19
Q

How can you input something=

A

use the input function

–> value is by default always a string so you must cast with numbers when needed i.e. int(input(“Type a number…))