4/16 Binary Hacks
def binary_multiply(num1, num2):
num1_int = int(num1, 2)
num2_int = int(num2, 2)
result = bin(num1_int * num2_int)[2:]
return result
num1 = input("Enter first binary number: ")
num2 = input("Enter second binary number: ")
result = binary_multiply(num1, num2)
print(f"{num1} x {num2} = {result}")
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)
# function 1: get summary statistics
summary = df.describe()
print(summary)
# function 2: group by gender and get average age and grade
grouped = df.groupby('Gender').agg({'Age': 'mean', 'Grade': lambda x: x.mode()[0]})
print(grouped)
# function 3: filter by age and grade
filtered = df[(df.Age >= 30) & (df.Grade.isin(['A', 'B']))]
print(filtered)
<!DOCTYPE html>
Student Gender Filter
Name | Gender | Grade |
---|---|---|
John | Male | 12 |
Maya | Female | 10 |
Josh | Male | 11 |
Carol | Female | 12 |
with open('valid_guesses.csv', 'r') as f:
word_list = []
for word in f:
word = word.strip()
if (word[0] not in ['a', 'b', 'c', 'd'] and word[-1] in ['a', 'b', 'c', 'd']):
word_list.append(word)
elif (word[0] in ['a', 'b', 'c', 'd'] and word[-1] not in ['a', 'b', 'c', 'd']):
word_list.append(word)
elif (word[0] not in ['a', 'b', 'c', 'd'] and word[-1] not in ['a', 'b', 'c', 'd']):
word_list.append(word + 'ism')
print(word_list)
simulations = [
{'name': 'Simulation A', 'time': 10.5, 'success': True},
{'name': 'Simulation B', 'time': 12.3, 'success': False},
{'name': 'Simulation C', 'time': 8.1, 'success': True},
{'name': 'Simulation D', 'time': 9.2, 'success': True},
{'name': 'Simulation E', 'time': 11.7, 'success': False}
]
# Sort by time and success
sorted_simulations = sorted(simulations, key=lambda s: s['time'])
sorted_simulations = sorted(simulations, key=lambda s: s['success'])
import random
# Create a list of possible outcomes
outcomes = [1, 2, 3, 4, 5, 6]
# Define the number of times to simulate the random number generator
num_simulations = 10
# Simulate the random number generator
for i in range(num_simulations):
outcome = random.choice(outcomes)
print(f"Simulation {i+1}: {outcome}")
from skimage import io
from matplotlib import pyplot as plt
waldo = io.imread('waldo.jpg')
plt.imshow(waldo)