Most of it Flashcards

1
Q

Control structures

A

building blocks of programming that manage the flow of a program based on conditions

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

Sequence structure

A

default control stucture, where instructions are executed one after another in order, e.g assigning a value to a variable, performing arithmetic operation

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

Iteration

A

refers to the process of repeating a block of code multiple times, used for repitition until condition is met. For loop and while loop.

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

Example of while loop

A

Initialize counter to 1
While counter is less than or equal to 10
Print counter
increment counter by 1
End while
In code =
total_sum = 0
number = -1
while number !=0:
number = int(input(“enter a number(0 to stop):”))
Total_sum =+ number
print(“total sum:”, total_sum)

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

Modular coding

A

Breaking down a complex problem into smaller, manageable parts.

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

Functions

A

Block of code designed to perform a task. It can take input process it and return it. In python the def keword is used follow by function name and parentheses.

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

Parameters

A

Functions can take any number of parameters, allowing you to pass data to the function

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

Charactersitics of modular coding

A

Cohesion - Each module should focus on 1 thing
Low coupling - interact with each other as little as possible
Encapsulation - Modules should hide their inner workings from other modules
Abstraction: Modules should provide a simple interface for others to use, hiding complex details

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

Local scope

A

Variables defined inside a function or block.
Def my_function():
local_var = “i’m local”
print(local_var)

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

Encapsulation

A

Binds together data and functions that manipulate data, keeping both safe from outside interface and misuse.
class Myclass
def_init_(self)
self.my_variable = “i’m encapsulated”
def my_method(self):
print(self.my_varaible)

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

Arrays

A

Collection of items stored at contiguous memory locations ; storing multiple items of the same type together to organize data more efficiently. Key features include fixed size, all elemnts must be same data type, elements can be accessed directly using their index number.

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

Properties of arrays

A

Properties of array:
index: array elements are accessed via indices
Size: the total number of elements that an array can hold
Fixed size: once declared, size of an array cant be changed

my_array[0] = 1
size = len(my_array)

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

Operations on arrays

A

Traversal: visiting each elemnent on the array
Insertion: addingan element to the array
Deletion: removing an element
Search: finding the location of an element
Update: changing an existing element to a new value

first_element = my_array[0] # access element
my_array[0] = 2 # update element
my_array.append(3) # insert element
def my_array[0] # delete element

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

One dimensional arrays

A

contains elements in a linear sequence, practical for storing data.

Practical
one_d_array = [1,2,3,4,5] # a one-dimensional array
print(one_d_array[0]) # accessing the first element

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

two dimensional arrays

A

organize elements in rows and columns
two_d_array = [[1,2,3],[4,5,6],[7,8,9]] # a 2 dimensional array
print(two_d_array[0][0] # accessing the first element of the first array

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

Advantages and disadvantages of arrays

A

Advantages:
- Simple and easy to use
-Efficient data storage and retireval for indexed data
-Basis for other data structures like strings

Disadvantages:
-Fixed size
-Poor perfomance for insertions and deletions compares to other data structures
- Does not offer dynamic resizing

17
Q

Dictionary

A

A dictionary is a collection of key-value pairs, where each key is unique and used to access its corresponding value.

Charactersitics : changeable, ordered insertions, can grow

e.g student_grades = {‘Alice’: 85, ‘Bob’:92, ‘Clara’: 88}
accessing it: print(my_dict[‘name’]) # output name
adding it: my_dict[‘age’] = 30
updating: my_dict[‘name’] = ‘Doe’
delete: del my_dict[‘name’]

18
Q

Dictionary iteration

A

for key in my_dict:
print(key)

19
Q

Use cases of dictionaries

A

Advantages:
- Fast access: lookup of values based on key is very efficient
- Flexible: keys can be any immutable type, making dictionaries versatile
Limitations:
- Unordered: older python libaries, dictionaries did not maintain order
-Memory usage: dictionaries comusme more memory than lists

20
Q

relational operators

A

== equals to
!= not equal to
> greater than
< less than
>= greater than or even
<= less than or even to

21
Q

OOP

A

the concept of “objects” which contain data in forms of fields(attributes) and code in the form of procedures(methods)

Encapsulation, abstraction, inheritancem and polymorphism

22
Q

Encapsulation

A

bundling of attribvutes and methods that operate on the data into a single unit called object to restrict direct access to an objects components.
Benefits:
- Improved security
- Simple interface while hiding complex implementation details

23
Q

Abstraction

A

the concept of hiding the complex reality while exposing only the essential parts.
Benefits:
- reduces complexity

24
Q

Inheritance

A

mechanism where a new class is created from an existing class
Benefits:
- Code reuse
- Establish a relationship between different classes through their objects