Unit 2

Bits, Bytes, Hexadecimal / Nibbles

  • Bits: binary digits(0/1)
  • Bytes: eight binary digits(ex: 00000001)
  • Hexadecimal: base 16, numbers are 1-10, A-F

Binary Numbers: Unsigned Integer, Signed Integer, Floating Point

  • Unsigned Integer: does not specify sign(+/-) of decimal number
  • Signed integer: specifies sign with first bit, 0 is positive, 1 is negative
  • Floating Point: stores number as "integer" and magnitude with power of 10 ex: 123 x 10^-1

Binary Data Abstractions: Boolean, ASCII, Unicode, RGB

  • Boolean: binary(yes/no, 0/1, true/false, etc.)
  • ASCII: general code for characters
  • Unicode: special characters
  • RGB: way of quantifying color with values of red, green, blue

Data Compression: Lossy, Lossless (note discussed yet)

Unit 3

Variables, Data Types, Assignment Operators

  • variables: word/characters that symbolize a value(s)
  • data types: integer, string, list, etc.
  • assignment operators: used to assign a variable to something(=)
variable = "value"

#data types
int = 1
str = "string"
list = ["a","b","c"]

#assignment operator =
this = "that"

Managing Complexity with Variables: Lists, 2D Lists, Dictionaries, Class

  • Lists: combination of multiple values
  • 2D List: list of lists, "rows and columns"
  • Dictionaries: stores data with key:value
  • Class:
list = ["1", "2", "3"]

#2D List
list2 = [("1.1", "1.2", "1.3"), ("2.1", "2.2", "2.3")]

#Dictionary
dict = {
    "name": "Jaden",
    "age": "15",
    "school": "del norte"
}

Algorithms, Sequence, Selection, Iteration

  • Algorithm: commands that do a certain task
  • Sequence: chronological order of tasks
  • Selection: do a certain action based on a condition
  • Iteration: repeating something until a condition is satisfied
binarylist = [
    "01001001", "10101010", "10010110", "00110111", "11101100", "11010001", "10000001"
]
newlist = []
def binary_convert(binary): #functino is an algorithm
    dec = 0
    i = 7
    for num in str(binary): #iteration
        if int(num) == 1: #selection
            dec += 2**i
            i -= 1
            continue
        else:
            i -= 1
            continue
    newlist.append(dec)

#everything next is sequencing

for x in binarylist:
    binary_convert(x)

print(newlist)

for new in newlist:
    if new > 100:
        newlist.remove(new)

print(newlist)

Expressions, Comparison Operators, Booleans Expressions and Selection, Booleans

  • Expressions: combination of operators/operands
  • Comparison operators: relatinoship between two numbers
  • Booleans Expressions: t/f, 0/1, y/n
3 + 4

#comparison operators
x > y 
x < y
x = y

# Booloeans
if x:
    print("false")
else:
    print("true")

Truth Tables

  • AND: 1 1
  • OR: 0 1, 1 0, 1 1
  • XOR: 0 0, 1 1
  • NOT: 0

Characters, Strings, Length, Concatenation, Upper, Lower, Traversing Strings

  • Character: single letter, number, symbol
  • Length: number of characters in a string
  • Concatenation: combining two things
  • Upper/Lower: change case
  • Traversing Strings: use index
str = "string"
len = len(str)
print(len)

#concatenation
str1 = "hel"
str2 = "lo"
str3 = str1 + str2
print(str3)

#traversing
string = "hello"
third = string[1]
print(third)

Python If, Elif, Else conditionals; Nested Selection Statements

  • if: do an action when something is true
  • elif: first condition false, test another
  • else: action when first condition false
  • nested selection: condition inside condition
num = 7

if num > 3:
    print("more than 3")
    if num > 5:
        print("more than 5")
else: 
    print("less than 3")

if num < 8:
    print("less than 8")
elif num < 4:
    print("less than 4")
more than 3
more than 5
less than 8

Python For, While loops with Range, with List
Combining loops with conditionals to Break, Continue

  • for: action for each x in y
  • while: loops as long as condition true
  • break: end loop
  • continue: keep loop
list = [1,2,3,4,5,6,7,8,9]

for x in list:
    if x < 5:
        print("less than 5")
    else:
        print("more than 5")

i = 0
while i < 5:
    print(list[i])
    i += 1
less than 5
less than 5
less than 5
less than 5
more than 5
more than 5
more than 5
more than 5
more than 5
1
2
3
4
5

Procedural Abstraction, Python Def procedures, Parameters, Return Values

  • def: defining a function to do a procedure
  • parameters: values given to a function to work with
  • return: brings variables out of function after running
def add5(x):
    x += 5
    return x

add5(5)
10