Binary Math

def binary_multiplication(a, b):
    """
    Multiplies two binary numbers and returns the result in both binary and decimal.
    """
    # Convert binary strings to integers
    num1 = int(a, 2)
    num2 = int(b, 2)
    
    # Multiply the numbers
    result = num1 * num2
    
    # Convert the result back to binary
    binary_result = bin(result)[2:]
    
    # Return the result in both binary and decimal
    return binary_result, result

# Get user input for binary numbers
binary1 = input("Enter first binary number: ")
binary2 = input("Enter second binary number: ")

# Multiply the binary numbers
binary_result, decimal_result = binary_multiplication(binary1, binary2)

# Print the result
print(f"{binary1} x {binary2} = {binary_result} (binary)")
print(f"{binary1} x {binary2} = {decimal_result} (decimal)")
1010 x 100101 = 101110010 (binary)
1010 x 100101 = 370 (decimal)

Binary Logic

image

import pandas as pd

# Load data from CSV file into a pandas DataFrame
df = pd.read_csv('random_numbers_1000.csv')

# Calculate the mean of the data
mean = df['number'].mean()

# Print the mean
print(f"The mean of the data is {mean}")

# Initialize a variable to keep track of the sum of the filtered data
filtered_sum = 0

# Initialize a variable to keep track of the count of numbers that meet the first criteria
count = 0

# Iterate over the data
for num in df['number']:
    if num % 2 != 0: # If the number is odd, skip it
        continue
    elif num % 5 == 0: # If the number is divisible by 5, multiply it by 2
        num *= 2
    else: # Otherwise, keep the number the same
        pass
    
    filtered_sum += num # Add the number to the sum
    count += 1 # Increment the count of numbers that meet the first criteria

# Calculate the mean of the filtered data
if count > 0:
    filtered_mean = filtered_sum / count
else:
    filtered_mean = 0

# Print the mean and the count of numbers that meet the first criteria
print(f"The mean of the filtered data is {filtered_mean}")
print(f"{count} numbers meet the first criteria")
The mean of the data is 0.4904628425744203
The mean of the filtered data is 0
0 numbers meet the first criteria

Logic Gates

  1. Logic gates are used to perform basic Boolean operations such as AND, OR, and NOT, which are the building blocks of more complex digital circuits that form the basis of modern computer functions.

  2. Boolean operations refer to the logical operations that can be performed on Boolean values, such as AND, OR, and NOT, while logic gates are physical electronic components that implement these Boolean operations in digital circuits.

  3. image

Fetching

orders = [
    {
        "id": 1,
        "customerName": "Alice",
        "items": [
            {"name": "Widget A", "price": 12.99},
            {"name": "Widget B", "price": 8.99},
            {"name": "Widget C", "price": 5.99},
        ],
        "orderDate": "2022-04-15",
        "total": 27.97,
    },
    {
        "id": 2,
        "customerName": "Bob",
        "items": [
            {"name": "Widget A", "price": 12.99},
            {"name": "Widget D", "price": 9.99},
        ],
        "orderDate": "2022-04-16",
        "total": 22.98,
    },
    {
        "id": 3,
        "customerName": "Charlie",
        "items": [
            {"name": "Widget C", "price": 5.99},
            {"name": "Widget E", "price": 7.99},
            {"name": "Widget F", "price": 10.99},
        ],
        "orderDate": "2022-04-18",
        "total": 24.97,
    },
]

def filter_orders_by_total(orders, min_total):
    """Filters orders by total, only returning orders with a total greater than or equal to min_total."""
    filtered_orders = []
    for order in orders:
        if order["total"] >= min_total:
            filtered_orders.append(order)
    return filtered_orders

filtered_orders = filter_orders_by_total(orders, 25.0)
print(filtered_orders)
[{'id': 1, 'customerName': 'Alice', 'items': [{'name': 'Widget A', 'price': 12.99}, {'name': 'Widget B', 'price': 8.99}, {'name': 'Widget C', 'price': 5.99}], 'orderDate': '2022-04-15', 'total': 27.97}]

GitHub Pages

One hosting service website that is different from Github Pages is Netlify. One advantage of Netlify is that it provides continuous deployment, which means that your website is automatically built and deployed whenever you push changes to your Git repository. This makes it very easy to iterate quickly and deploy changes frequently, without having to worry about the deployment process. Additionally, Netlify provides a lot of other features such as custom domain support, SSL encryption, and forms handling, making it a great choice for static website hosting.

API's

import pandas as pd

data = {
    'Name': ['Dillon', 'Noor', 'Steven', 'Lucas', 'Harsha', 'Varalu', 'Ryan', 'Emaad'],
    'Age': [24, 31, 42, 27, 29, 26, 90, 15],
    'Gender': ['M', 'M', 'M', 'M', 'F', 'F', 'F', 'F'],
    'Grade': ['A', 'B', 'A', 'D', 'C', 'F', 'B', 'A']
}

df = pd.DataFrame(data)

# 1. Use the describe function to get summary statistics for the numeric columns
print(df.describe())

# 2. Use the value_counts function to get the count of each gender
print(df['Gender'].value_counts())

# 3. Use the groupby function to get the mean age by gender
print(df.groupby('Gender')['Age'].mean())
             Age
count   8.000000
mean   35.500000
std    23.268618
min    15.000000
25%    25.500000
50%    28.000000
75%    33.750000
max    90.000000
M    4
F    4
Name: Gender, dtype: int64
Gender
F    40.0
M    31.0
Name: Age, dtype: float64