3.3 Summary (We Taught)

Algorithms

Definition of an algorithm: A set of instructions to do a task.

Parts of an Algorithm

Sequencing:

The order of the steps, how they are done. For example, baking cookies: You make the dough, and then prepare it. Not the other way around.

Selection:

Conditional Statements used to decide the process of a program: If __ then ___.

Iteration:

Repeating steps of the algorithm until something is done or finished. Such as, keep on cutting the watermelon until there is x amount of parts. Example:

#Example 1: Algorithm for cutting fruits
# Function to cut fruits
def cut_fruits():
    # Sequencing: The steps must happen in the order of the code.
    print("Step 1: Wash the fruits.")
    print("Step 2: Peel the fruits if necessary.")
    
    # Selection: Making a decision based on a condition.
    fruit_type = input("What type of fruit are you cutting? (apple, orange, or banana)").strip().lower()
    
    if fruit_type == "apple":
        print("Step 3: Cut the apple into slices.")
    elif fruit_type == "orange":
        print("Step 3: Peel and separate the orange slices.")
    elif fruit_type == "banana":
        print("Step 3: Peel and cut the banana into chunks.")
    else:
        print("Step 3: Fruit not recognized, proceed with cutting as desired.")
    
    print("Step 4: Serve the fruits.")

    # Iteration: Repeat slicing until you finish all the fruits.
    fruits_left = int(input("How many more fruits do you have to cut? "))
    
    while fruits_left > 0:
        print("Cutting another fruit...")
        fruits_left -= 1
    
    print("All fruits are cut and ready to serve!")

cut_fruits()

Mathematical Operations

Operation Symbol Description
Addition + Sum of a and b
Subtraction - Difference of a and b
Multiplication * Product of a and b
Division / Quotient of a divided by b
Modulus % Remainder of a divided by b

3.5 Summary (We Taught)

Relational operators in JavaScript/Python are used to compare two values, returning a Boolean (true or false). Common operators include:

  • ==: Equal to (checks value equality).
  • !=: Not equal to (checks value inequality).
  • ===: Strictly equal (checks value and type).
  • !==: Strictly not equal (checks inequality in value and type).
  • > and <: Greater than / Less than.
  • >= and <=: Greater than or equal to / Less than or equal to.

These are useful in everyday scenarios, like comparing ages or verifying passwords.

#Example 2: Using Relational Operators
a = 5
b = 10

print(a == b)  # Equal to
print(a != b)  # Not equal to
print(a > b)   # Greater than
print(a < b)   # Less than
print(a >= b)  # Greater than or equal to
print(a <= b)  # Less than or equal to

Hacks Done

Below is a table linking to all my other 3. blank hacks.

Hack Number Description Link
Hack 3.1 Homework Hacks 3.1 Hack 3.1
Hack 3.2 Homework Hacks 3.2 Hack 3.2
Hack 3.4 Homework Hacks 3.4 Hack 3.4
Hack 3.6 Homework Hacks 3.6 Hack 3.6
Hack 3.7 Homework Hacks 3.7 Hack 3.7
Hack 3.8 Homework Hacks 3.8 Hack 3.8
Hack 3.10A Homework Hacks 3.10A Hack 3.10A
Hack 3.10B Homework Hacks 3.10B Hack 3.10B

Summary of What We Learned

Hack 3.1: Homework Hacks 3.1

In this hack, we covered the basics of arithmetic operations in Python. We learned how to perform addition, subtraction, multiplication, division, and modulus operations. This hack provided a solid foundation for understanding how to manipulate numerical data in Python. We also explored the concept of variables, which act as storage locations for data, allowing us to easily reference and manipulate values.

Hack 3.2: Homework Hacks 3.2

This hack focused on advanced arithmetic operations and introduced us to concepts like exponentiation and floor division. We also explored the use of built-in mathematical functions to perform complex calculations. Additionally, we delved into data abstraction, which involves simplifying complex data structures by focusing on essential details and ignoring the rest.

Hack 3.4: Homework Hacks 3.4

This hack focused on string manipulation techniques. We explored various methods to manipulate strings, including concatenation, slicing, and formatting. Understanding these techniques is crucial for handling text data effectively in Python. We also learned about strings, which are sequences of characters used to represent text.

Hack 3.6: Homework Hacks 3.6

In this hack, we delved into data structures. We learned about lists, dictionaries, and sets, and how to use them to store and manipulate collections of data. This knowledge is essential for organizing and accessing data efficiently in Python. Lists, in particular, are data structures that store multiple values in a single variable, allowing for efficient organization and manipulation of data.

Hack 3.7: Homework Hacks 3.7

This hack introduced us to control flow statements. We covered if-else statements, loops, and how to use them to control the execution of code based on certain conditions. Mastering control flow is key to writing dynamic and responsive programs. We also explored booleans, which represent true or false values, and conditionals, which allow decisions to be made based on whether a condition is true or false.

Hack 3.8: Homework Hacks 3.8

In this hack, we explored functions and modular programming. We learned how to define and call functions, pass arguments, and return values. This hack emphasized the importance of breaking down code into reusable and manageable pieces. We also covered nested conditionals, which are conditional statements placed inside other conditional statements, allowing for more complex decision-making.

Hack 3.10A: Homework Hacks 3.10A

This hack focused on file handling in Python. We learned how to read from and write to files, handle exceptions, and work with different file formats. This is crucial for managing data persistence in applications. Additionally, we explored iteration, which involves repeatedly executing a block of code, typically using loops.

Hack 3.10B: Homework Hacks 3.10B

In this hack, we explored working with external libraries and APIs. We learned how to install and use third-party libraries, make HTTP requests, and process JSON data. This hack highlighted the importance of leveraging external resources to extend the functionality of our programs.