Unit 2 - Binary/Data Terms

  • Bits: binary digits, smallest unit of data processed by a computer (1 or 0, true or false)
  • Bytes: 8-bit unit, unit of data that is eight binary digits(bits) long
  • Hexadecimal: Numbering system with base 16, digit values from 0-9 then A-F
  • Nibbles: Four binary digits(bits), half of a byte
  • Binary numbers: Numbers expressed in base 2 numeral system, digit values 0-1
  • Unsigned Integer: 32-bit encoding non negative integers, integers with no + or - sign associated with them, range of [0 to 4294967295]
  • Signed Integer: 32-bit including negative integers, range of [-2147483648 to 2147483647]
  • Floating Point: Number with decimal point "."
  • Binary Data Abstractions: Using binary(1 and 0, True and False) to sort through data and only preserve information that is relevant in a given context, and forgetting information that is irrelevant in that context
  • Boolean: Binary variable, two possible values true and false
  • ASCII: standard data-encoding format for electronic communication between computers, 1 byte to represent characters
  • Unicode: universal character encoding standard, roughly 100000 characters to represent characters of different languages, 4 bytes to reperesent characters
  • RGB: color model of red, green, and blue, system for representing the colors to be used on a computer display
  • Data Compression: process of encoding, restructuring or otherwise modifying data in order to reduce its size
  • Lossy: data encoding and compression technique that deliberately discards some data in the compression process
  • Lossless: restores and rebuilds file data in its original form after the file is decompressed, no loss of data even after decompression

Unit 3… Algorithm/Programming Terms

Variables, Data Types, Assignment Operators Managing Complexity with Variables: Lists, 2D Lists, Dictionaries, Class Algorithms, Sequence, Selection, Iteration Expressions, Comparison Operators, Booleans Expressions and Selection, Booleans Expressions and Iteration, Truth Tables Characters, Strings, Length, Concatenation, Upper, Lower, Traversing Strings Python If, Elif, Else conditionals; Nested Selection Statements Python For, While loops with Range, with List Combining loops with conditionals to Break, Continue Procedural Abstraction, Python Def procedures, Parameters, Return Values

Unit 3 - Algorithm/Programming Terms

Variables

  • a symbolic name that is a reference or pointer to an object
  • example:
x = 1
print(x)

name = "Aliya"
print(name)
1
Aliya

Data Types

  • classifaction or categorization of data items
  • example of main data types below:
a = 20 # int
b = 35.75 # float
c = 1+3j # complex

# Boolean
d = True
e = False

# Set
f = {2, 4, 6}

# Dict
g = {1:'a', 2:'b'}

# Sequence
h = "Aliya" # string
i = [2, 'a', 5.7] # list
j = (3, 4.5, 'b') # tuple

Assignment Operators

  • used to perform operations on values and variables
  • special symbols that carry out arithmetic, logical, bitwise computations
a = 1+3 # assign value of right side of expression to left side operand
print(a)

b = 2
b += 3 # (2+3) add and assign: add right side operand with left side operand and then assign to left operand
print(b)

c = 10
c -= 1 # (10-1) subtract and: subtract right operand from left operand and then assign to left operand
print(c)
4
5
9

Managing Complexity With Variables

  • Lists: store multiple items in a single variable
  • 2D lists: array of arrays that can be represented in matrix form, like rows and columns
  • Dictionaries: consists of a collection of key-value pairs, each key-value pair maps the key to its associated value
  • Class: code template for creating objects
  • For loop: repeat a specific block of code a known number of times
  • Iteration: sequence of instructions or code being repeated until a specific end result is achieved
  • If/elif/else: conditional statements that provide you with the decision making that is required when you want to execute code based on a particular condition
  • Nested conditionals: an if/elif/else statement inside another f/elif/else statement

Examples below:

exlist = [4,-5,-2,0,3,6,7,5] # list
pos = []
neg = []

for i in exlist: # for loop, iteration with list
    if int(i) > 0: # if conditional statement, comparison operator greater than
        pos.append(i)
    elif int(i) < 0: # elif conditional statement, comparison operator less than
        neg.append(i)
    else: # else conditional statement
        if int(i) == 0: # nested conditionals - if inside elif statement, in this ex it is basically just elif statement
            print("Zero")

print(pos)
print(neg)
Zero
[4, 3, 6, 7, 5]
[-5, -2]
  • While loop: repeat a specific block of code an unknown number of times, until a condition is met
  • Comparison operator: compare the contents in a field to either the contents in another field or a constant
  • String concatentation: operation of joining two strings together
  • Return values: value that a function returns to the calling script or function when it completes its task
nums = [] # list
x = int(input("Enter a number between 1 and 255:"))

def convert(x): # python def, defining a function
    if x >= 1 and x <= 255: # if statement, greater than or equal to and less than or equal to comparison operator
        while x/2 != 0: # while loop
            rem = x % 2 # mathmatical operator % which finds remainder
            nums.append(rem)
            x = int(x/2)
        nums.reverse()
        binary = " " # string, it is empty for now
        for i in nums: # for loop with list, iteration for loop
            binary = binary + str(i) # concatenation of strings binary and i
        return binary # return values out of the function
    else: # else statement for number that is not fit for the code
        print("Number not within range.")

print(str(x) + " to binary: " + convert(x))
6 to binary:  110
  • Length: len() returns length of an object
names = ["jaden","max","dylan","orlando"]

def length(names): 
    for x in names:
        print("Length of " + x + ": " + str(len(x))) # len finds the length of or the number of items in this list

length(names)

your_name = input("What's your name?:")
print("Your name is " + str(len(your_name)) + " letters long.")

vowels = 0
cons = 0

for l in your_name: # for loop iterating through each of the names in the list above
    if l == "a" or l == "e" or l == "i" or l == "o" or l =="u":
        vowels += 1
    else:
        cons += 1

# parametersin this case are vowels and consonants
print("Your name has " + str(vowels) + " vowels.")
print("Your name has " + str(cons) + " consonants.")
Length of jaden: 5
Length of max: 3
Length of dylan: 5
Length of orlando: 7
Your name is 5 letters long.
Your name has 2 vowels.
Your name has 3 consonants.
import time
numlist = [1,3,5,7,9,11,13,15,17,19]
valuelist = [0,3,6,9,12,15,18,21]
def isvalue(value,array):
    upper = (len(array)-1) # upper value
    lower = 0 # lower value
    while upper > lower:
        middle = (lower+upper)//2
        if middle == value:
            return True
        elif middle > value:
            upper = middle - 1
        else:
            lower = middle + 1
    return False

starttime = time.time()
for i in range(100000): # for loop with range, in this case it is for every number until 10000
    for i in range(len(valuelist)):
        x = isvalue(valuelist[i],numlist)
endtime = time.time()
print(endtime-starttime,'seconds') 
0.4087941646575928 seconds