CSC115 Final Flashcards

(83 cards)

1
Q

What are the arithmetic operators in Python?

A

+ : addition
- : subtraction
* : multiplication
/ : division
// : floor division (removes decimal)
% : modulus (returns remainder)
** : exponentiation

Python follows PEMDAS for order of operations.

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

What is the difference between pseudocode and an algorithm?

A

Algorithm: Step-by-step instructions for solving a problem.
Pseudocode: A human-readable version of an algorithm using programming-like syntax.

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

What does a flowchart do?

A

A visual diagram that shows the flow of a program’s logic.

Uses symbols like: Oval: Start/End, Parallelogram: Input/Output, Rectangle: Process, Diamond: Decision (if/else)

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

What are the components of the Input → Process → Output model?

A

Input: Data received (e.g., user typing)
Processing: Logic and calculations applied to input
Output: Final result shown to user.

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

What are the types of computer memory?

A

RAM: Volatile memory, erased when power is off.
Secondary Storage: Long-term memory like hard drives (retains data after shutdown).
Main Memory refers to RAM.

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

What is camelCase?

A

Variable naming where the first word is lowercase, and each subsequent word starts with uppercase.

Example: totalScore, userInput

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

How are expressions evaluated in Python?

A

Python follows math precedence (PEMDAS):
1. **
2. *, /, //, %
3. +, -

Parentheses can override this order.

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

What are named constants in Python?

A

Assigned once, not changed later.
Written in ALL CAPS: PI = 3.14.

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

What are logical operators in Python?

A

and: True if both conditions are true.
or: True if at least one condition is true.
not: Reverses Boolean value.

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

What are augmented assignment operators?

A

+=, -=, *=, /=, %=, **= etc.
Shortcuts for updating variables: x += 1 means x = x + 1.

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

What is the difference between global variables and global constants?

A

Global variable: declared outside all functions, accessible globally.
Global constant: conventionally ALL CAPS, should not be changed.

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

What are some functions in the math module?

A

ceil(x) – rounds up to the nearest integer
floor(x) – rounds down
sqrt(x) – square root
hypot(x, y) – hypotenuse = √(x² + y²).

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

What is the difference between random() and uniform()?

A

random() – float from 0.0 to 1.0
uniform(a, b) – float between a and b.

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

What is the syntax for using range()?

A

Syntax: range(start, stop, step)

Example: range(1, 10, 2) → 1, 3, 5, 7, 9

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

What are functions in modules?

A

Modules are .py files with functions and variables.

Example: import mymodule
mymodule.greet()

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

What are the file modes in Python?

A

‘r’ – read
‘w’ – write (overwrites file)
‘a’ – append
‘w’ clears the file if it exists.

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

What is the difference between lists and tuples?

A

List: [], mutable
Tuple: (), immutable
Use tuples when data shouldn’t change.

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

What is the difference between ValueError and IOError?

A

ValueError: wrong value (e.g., int(“abc”))
IOError: file errors (e.g., file not found)
except catches errors to prevent crashes.

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

What are records in files?

A

One line = one record
Can store records as list items or dictionaries.

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

What is a program?

A

A program is a set of instructions executed by a computer.

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

What is RAM?

A

RAM = volatile memory; used temporarily while running.

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

What is secondary storage?

A

Secondary storage = hard drive, retains data long-term.

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

What is a byte?

A

Byte = 8 bits.

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

What does the CPU understand?

A

CPU understands only machine language (binary).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is hardware?
Hardware = physical components.
26
What is a bit?
Bit off = 0; bit on = 1.
27
What is a video display?
Video display = output device.
28
What are the arithmetic operators?
+ : Addition - : Subtraction * : Multiplication / : Division (returns float) // : Floor Division (no decimal) % : Modulus (remainder) ** : Exponentiation (power) // = integer division % = modulus (remainder) Python follows PEMDAS (not strict left-to-right).
29
What does 'or' mean in logic?
or – true if either part is true.
30
What do flowcharts use for decision making?
Decision and repetition in flowcharts use diamonds.
31
What is a while loop?
while count < 1 with count = 10 runs 0 times.
32
What is the exit condition for a while loop?
while num != 999 → ends when num == 999.
33
What must all block statements be in Python?
All block statements must be indented.
34
What happens if there is a missing exit in a loop?
Missing exit = infinite loop.
35
What is the first line of a function?
First line = header (def name():).
36
What does it mean to call a function?
Called = executed.
37
What do value-returning functions use?
Value-returning functions use return.
38
What is the difference between an argument and a parameter?
Argument = passed in; Parameter = receives value.
39
What starts a function definition?
Starts with def.
40
What are the naming rules for functions?
Same naming rules as variables.
41
What is the difference between defining and executing a function?
Defining ≠ executing.
42
What does def my_func(a, b, c); my_func(3,2,1) do?
a = 3.
43
What happens when changing parameters?
Changing parameters doesn’t change arguments.
44
What does print(magic(5)) with return value do?
→ 25.
45
What does import math do?
import math → access math tools.
46
What does import turtle do?
import turtle → turtle graphics.
47
What does ceil(3.4) return?
ceil(3.4) = 4; floor(3.4) = 3.
48
What is the result of (2 + 6)/4?
(2 + 6)/4 = 2.0.
49
What is procedural programming?
The procedural programming practice is centered on creating functions that are separate from the data they work on.
50
What is object-oriented programming?
The object-oriented programming practice is centered on creating objects.
51
What is a data attribute?
A data attribute is a component of a class that stores data.
52
What is an instance?
An instance is a specific object created from a class.
53
How do you hide a class attribute?
To hide a class attribute from outside code, begin the attribute name with two underscores.
54
What is an accessor method?
An accessor method retrieves the value of a data attribute without changing it.
55
What is a mutator method?
A mutator method modifies or sets the value of a data attribute.
56
What is the __init__ method?
The __init__ method is automatically called when an object is created.
57
What is a getter and setter?
Getter = Accessor, Setter = Mutator.
58
What is UML?
UML = Unified Modeling Language.
59
What is the difference between procedural programming and OOP?
Procedural programming: functions and logic separate from data Object-oriented programming (OOP): centered around objects and classes.
60
What does a class have?
A class has: Data attributes: store state (e.g., self.name) Methods: define behaviors.
61
What is an instance in OOP?
Instance: An object created from a class.
62
What is an accessor (getter)?
Accessor (getter): gets a value.
63
What is a mutator (setter)?
Mutator (setter): sets or changes a value.
64
What is the constructor method in OOP?
__init__ is the constructor method called when an object is created.
65
How do you hide an attribute in OOP?
Start attribute name with __ to hide it (name mangling).
66
What is recursion?
A recursive function calls itself.
67
What is the depth of recursion?
The depth of recursion refers to how many times a function calls itself.
68
What is the base case in recursion?
The base case is the part of the problem that can be solved without recursion.
69
What is the recursive case?
The recursive case is the part of the problem that must be solved using recursion.
70
What is direct recursion?
When a function explicitly calls itself, it's called direct recursion.
71
What is indirect recursion?
When function A calls B, which calls A, it's called indirect recursion.
72
Can any problem solved recursively be solved with a loop?
Any problem that can be solved recursively can also be solved with a loop.
73
What does a recursive function need to prevent infinite recursion?
A recursive function needs a base case to prevent infinite recursion.
74
What happens in the base case of recursion?
In the base case, a recursive method does not call itself.
75
How do recursive algorithms compare to loop algorithms?
Algorithms that use loops usually run faster than equivalent recursive algorithms.
76
What is a recursive function?
A recursive function calls itself.
77
What is a base case?
Base case: condition where recursion stops.
78
What is a recursive case?
Recursive case: where function continues calling itself.
79
What is direct recursion?
Direct recursion: function calls itself.
80
What is indirect recursion?
Indirect recursion: function A calls B, which calls A.
81
Can recursive problems be solved with loops?
Any recursive problem can also be solved using a loop.
82
What do recursive functions need to avoid infinite recursion?
Recursive functions need a base case to avoid infinite recursion.
83
How do recursive functions compare to loops in terms of speed?
Recursive functions are generally slower than loops.