Btw: I did all of the games but I had to click run all and I didn’t want to redo all of them
Popcorn Hack 1
binary_num = "1011"
decimal_value = 0
for pos, x in enumerate(reversed(binary_num)):
if x == "1":
decimal_value += 2 ** pos
print(decimal_value)
11
Popcorn Hack 2
import random
import time
def binary_addition_battle():
# Generate two random binary numbers (up to 8 bits)
num1 = bin(random.randint(0, 255))[2:]
num2 = bin(random.randint(0, 255))[2:]
# Show the binary numbers
print(f"Add the following binary numbers:")
print(f"Number 1: {num1}")
print(f"Number 2: {num2}")
# Start the timer
start_time = time.time()
# Ask the user for the sum
user_answer = input("Your answer (in binary): ")
# End the timer
end_time = time.time()
# Calculate the correct binary sum
correct_answer = bin(int(num1, 2) + int(num2, 2))[2:]
# Check if the answer is correct
if user_answer == correct_answer:
print(f"Correct! You took {end_time - start_time:.2f} seconds.")
print(f"Your score: +10 points!")
else:
print(f"Oops! The correct answer was {correct_answer}.")
print(f"Your score: -5 points.")
# Run the game
binary_addition_battle()
Add the following binary numbers:
Number 1: 110001
Number 2: 1101000
Oops! The correct answer was 10011001.
Your score: -5 points.
Popcorn Hack 3
import random
def binary_subtraction(bin1, bin2):
max_len = max(len(bin1), len(bin2))
bin1 = bin1.zfill(max_len)
bin2 = bin2.zfill(max_len)
result = ''
borrow = 0
for i in range(max_len-1, -1, -1):
bit1 = int(bin1[i])
bit2 = int(bin2[i])
sub = bit1 - bit2 - borrow
if sub == 0 or sub == 1:
result = str(sub) + result
borrow = 0
elif sub == -1:
result = '1' + result
borrow = 1
elif sub == -2:
result = '0' + result
borrow = 1
result = result.lstrip('0') or '0'
return result
print("🧠 Binary Subtraction Challenge! 🧠")
score = 0
total_questions = 3
for question_num in range(1, total_questions + 1):
num1 = random.randint(8, 63)
num2 = random.randint(0, num1)
bin1 = bin(num1)[2:]
bin2 = bin(num2)[2:]
print(f"\nProblem {question_num}: {bin1} - {bin2}")
user_answer = input("Your answer: ").strip()
correct_answer = binary_subtraction(bin1, bin2)
if user_answer == correct_answer:
print("✅ Correct!")
score += 1
else:
print(f"❌ Incorrect. The correct answer was {correct_answer}.")
print(f"\n🎯 You got {score}/{total_questions} correct!")
print("Thanks for practicing!")
🧠 Binary Subtraction Challenge! 🧠
Problem 1: 110001 - 11
❌ Incorrect. The correct answer was 101110.
Problem 2: 100000 - 10110
❌ Incorrect. The correct answer was 1010.
Problem 3: 101000 - 111
❌ Incorrect. The correct answer was 100001.
🎯 You got 0/3 correct!
Thanks for practicing!
AP MC Questions
q28: D
q36: B
q42: D
q44: B
Homework Hack
-
To convert binary to decimal, you start at the last position and if the number is 1, you do 2^position (starting from 0) and go through the number.
-
235