Material That Has Been Covered

See Daily Notebooks and Hacks for More Help on Any Of These Topics!

  • Variables, Assignments, and Data Abstractions
  • Mathematical Expressions and Strings
  • Boolean Expression, Conditionals, and Nested Conditionals
  • Boolean Iteration and Lists
  • Developing Algorithms and Binary Search
  • Calling and Developing Procedures

Unit 2 Binary/Data Terms and Unit 3 Algorithm/Programming Terms

Variables

a value that can change, depending on conditions or on information passed to the program.

fruit = "apple" #fruit is the name, 'apple' is the value, and string is the type
score = 0 #score is the name, 0 is the value, integer is the type

Data Types

  • String (or str or text) - combination of any characters
    • Character (or char) - single letters
    • Integer (or int) - whole numbers
    • Float (or Real) - numbers that contain decimal points, or for fractions.
    • Boolean (or bool) - data is restricted to True/False or yes/no options
integer = 9

string = "words" #surrounded by quotations

boolean = False # True or false

Assignment Operators

operator used to assign a new value to a variable.

Operator Description Syntax Outcome when print(a)
= Assign value of right side of expression to left side operand a = b b
+= Add right side operand with left side operand and then assign to left operand a += b a + b
-= Subtract right operand from left operand and then assign to left operand: True if both operands are equal a -= b a - b
*= Multiply right operand with left operand and then assign to left operand a *= b a * b
/= Divide left operand with right operand and then assign to left operand a /= b a / b
**= Calculate exponent(raise power) value using operands and assign value to left operand a **= b a ^ b

Lists

an abstract data type that represents a finite number of ordered values, where the same value may occur more than once.

fruits = ["apple", "grape", "strawberry"]
print (fruits)
['apple', 'grape', 'strawberry']

2D Lists

a two-dimensional array can hold more than one set of data

keyboard = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [" ", 0, " "]]

def print_matrix4(matrix):
    for i in matrix:
        print('\t'.join(map(str, i)))
        
print_matrix4(keyboard)
1	2	3
4	5	6
7	8	9
 	0	 

Dictionaries

an abstract data type that defines an unordered collection of data as a set of key-value pairs

quiz = {"Who is the author of It Ends With Us":["a. Holly Jackson","b. Colleen Hoover", "c. Lisa Jewell", "d. Jennifer Barnes"], "Who is the author of Percy Jackson":["a. JK Rowling", "b. Holly Jackson","c. Rick Riordan", "d. Colleen Hoover"]
, "When was a Good Girl's Guide to Murder Published":["a. 2019","b. 2018", "c. 2020", "d. 2021"], "When was It Starts with Us Published":["a. 2019","b. 2020", "c. 2021", "d. 2022"]}

# for the answers, used the question as the key and the multiple choice letter as the value 
answers = {"Who is the author of It Ends With Us":"b", "Who is the author of Percy Jackson":"c", "When was a Good Girl's Guide to Murder Published":"a", "When was It Starts with Us Published":"d"}
count = 0

# iterating through the dictonary's keys and values 
for k,v in quiz.items():

# printing the key and it's values 
    print(k)
    print(*v, sep = '\n')

# taking the user input for the answer, entering ab
    user_input = input("Enter Your Answer")

# comparing that with the answer's value 
    if(answers.get(k)==user_input):

        # incrementing the count 
     count = count +1

# printing the user's score
print('You got', count, 'correct answers')    
Who is the author of It Ends With Us
a. Holly Jackson
b. Colleen Hoover
c. Lisa Jewell
d. Jennifer Barnes
Who is the author of Percy Jackson
a. JK Rowling
b. Holly Jackson
c. Rick Riordan
d. Colleen Hoover
When was a Good Girl's Guide to Murder Published
a. 2019
b. 2018
c. 2020
d. 2021
When was It Starts with Us Published
a. 2019
b. 2020
c. 2021
d. 2022
You got 4 correct answers

Algorithms

  • a list set of instructions, used to solve problems or perform tasks.
    • Sequence: algorithms do tasks in the order of specification.
    • Selection: helps choose two different outcomes based off a decision.
    • Iteration: if a condition is true, then the code can repeat.

Expressions

combination of values and functions that are combined and interpreted to create a new value.

  • x + y Addition
  • x - y Subtraction
  • x * y Multiplication
  • x / y Division
  • x // y Quotient
  • x % y Remainder
  • x ** y Exponentiation

Comparison Operators

compares two values against one another.

  • a = b - equal to
  • a (not equal to symbol) b - not equal to
  • a > b - greater than
  • a < b - less than
  • a (is greater than or equal to symbol) b - greater than or equal to
  • a (is less than or equal to symbol) b - less than or equal to

Boolean Expressions and Selection/Iteration

if a condition is true or false, there is a differnet outcome and if a condition is true, the code repeats an earlier step.

num = 5

# selection:
if num < 100 : 
    print("The number is small")
else: 
    print ("The number is large")
    
# iteration: 

while num < 10:
    num = num + 1
    print(num)
The number is small
6
7
8
9
10

Truth Tables

  • have two values
    • 0 = off, false
    • 1 = on, true
    • Examples
      • 0 and 0 = false. And operator means both needs to be true.
      • 0 or 1 = true. Either or.
      • Use this in conditionals (selection).
      • AND = Both A AND B must be true for the overall operation to be true
      • XOR = Either A OR B must be true for the overall operation to be true, except if both are true then the overall outcome is F again
      • Or = Either A OR B must be true for the overall operation to be true

AND truth tables


A B Outcome
F F F
F T F
T F F
T T T

OR truth tables


A B Outcome
F F F
F T T
T F T
T T T

XOR truth tables


A B Outcome
F F F
F T T
T F T
T T F


Ex: A is true, B is false

Bits

most basic unit of informartion in computing.

binary digit that is the smallest increment of data on a computer ex. 0 and 1

Bytes

a group of 8 digits or bits operating as one unit.

ex. 12,345,678

Hexadecimal / Nibbles

base/positional number system used in mathematics and computer science (base 16 numbering system)

Binary Numbers

a binary digit, or bit, is the smallest unit of data. numbers expressed in the base two numbering systems. they are only 0s and 1s.

Unsigned Integer

non-negative integers.

integers that don't have a sign associated with them

  • ex. 1, 2

Signed Integer

32-bit datum, encodes an integer in the range ([-2147483648 to 2147483647]).

A signed integer is a 32-bit datum that encodes an integer in the range [-2147483648 to 2147483647]

  • ex - 100, 80

Floating Point

a positive or negative whole number with a decimal point.

examples: 5.2, 333.09, etc.

Binary Data Abstractions

reducing data to simplify it's entirety.

Boolean

logical data type that can have only the values true or false.

brands = ["nike", "adidas", "underarmour"] #string
numbers = [1, 2, 3, 4, 5] #integer
truefalse = [True, False, True] #boolean

ASCII

a character encoding scheme in which each character is represented by a 7-bit (originally) or 8-bit binary sequence.

Unicode

16-bit character set which describes all of the keyboard characters.

  • ex: emojis

RGB

a problem solving approach (algorithm) to find a satisfactory solution where finding an optimal or exact solution is impractical or impossible.

Data Compression

the process of encoding data so that is needs fewer bits/bytes to represent it.

Lossy

data encoding and compression technique that deliberately discards some data in the compression process.

Lossless

data compression algorithm that allows the original data to be perfectly reconstructed from the compressed data

x = True
y = False

Class

written in a defined structure to create an object.

class MyClass:
  x = 5

Characters

display unit of information equivalent to one alphabetic letter or symbol.

  • ex: ex. a, 8, #

Strings

ordered sequences of characters.

string = "hello"

Length

len ()
len("supercalifragilisticexpialidocious") 
34

the number of symbols output.

Concatenation

String concatenation is combining 2 or more strings to make a new strings in order to create a new string

concat() in pseudocode and varys from language to language can be used to combine to strings such as concat("cookie","monster") returns cookiemonster

string1 = "book"
string2 = "case"

Upper

used to check if the argument contains any uppercase characters.

  • returns "True" if all characters in the string are uppercase, Otherwise, It returns "False".

Lower

returns the lowercase string from the given string.

Traversing Strings

the process of going through a String one character at a time, often using loops.

Python If, Elif, Else conditionals

  • If: statement executes a piece of code when one statement is false and the following statement is true.
  • Elif: first if statement isn't true, but want to check for another condition.
  • Else: executes if "if" isn't true.
hours = 30
sal = ""
experienced = True
# using operators to determine the salary
if (hours >= 10):
    sal = "150k"
elif (hours >= 8):
    sal = "90k"
else:
    sal = "50k"
    experienced = False
# printing the final statement 
print ('The person has a salary of:' , sal,'and has experience:' , experienced)
The person has a salary of: 150k and has experience: True

Nested Selection Statements

when more than one decision must be made before the appropriate action can be taken.

Python For While loops with Range with List

returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number.

  • For: Process stops if next element meets statement
  • While: Process is repeated until statement is met

Combining loops with conditionals to Break, Continue

a statement that controls the flow of execution depending on some condition.

Procedural Abstraction

have variable parameters.

Python Def procedures

procedure allows us to group a block of code under a name, known as a procedure name.

Parameters

variable used in a function to refer to one of the pieces of data provided as input to the function.

Return Values

function returns to the calling script or function when it completes its task.