Nighthawk Pages

Base HW

HW Hacks

AP Exam Prep

Popcorn Hack

Popcorn Hacks 1:

  • 101010 - 42
  • 12301 (this is not a binary numbers, so we cannot convert it).
  • 11001 - 25, and it is binary.


Popcorn Hack 2:

  • The result would be false. You have to do the “and” operation first, so it ends up coming out as false.


Popcorn Hack 3:

  • The result would be true. You do the “not” operation first, and the “and” finally, “or” which gives us true.


def decimal_to_binary(n):
    if n >= 0:
        return bin(n)[2:]  # Remove the '0b' prefix
    else:
        return '-' + bin(abs(n))[2:]

def binary_to_decimal(b):
    if b.startswith('-'):
        return -int(b[1:], 2)
    else:
        return int(b, 2)

# Test Cases
test_decimals = [10, -10, 0, 255, -255]
test_binaries = ["1010", "-1010", "0", "11111111", "-11111111"]

print("Decimal to Binary:")
for number in test_decimals:
    print(f"{number}{decimal_to_binary(number)}")

print("\nBinary to Decimal:")
for binary_str in test_binaries:
    print(f"{binary_str}{binary_to_decimal(binary_str)}")
Decimal to Binary:
10 → 1010
-10 → -1010
0 → 0
255 → 11111111
-255 → -11111111

Binary to Decimal:
1010 → 10
-1010 → -10
0 → 0
11111111 → 255
-11111111 → -255
import time

difficulty = input("Enter difficulty (easy, medium, hard): ").lower().strip()

while difficulty not in ["easy", "medium", "hard"]:
    print("Please enter a valid difficulty level.")
    time.sleep(0.5)
    difficulty = input("Enter difficulty (easy, medium, hard): ").lower().strip()

print("Difficulty set to:", difficulty)

Difficulty set to: easy
Scroll to top