Popcorn Hack 1:
- 101010 is binary because all numbers are 1s and 0s
- 12301 is not because it has a 2 and a 3
- 11001 is binary all 1s and 0s
Popcorn Hack 2:
- 101+110 = 1011
- 1101-1011 = 010
- 111+1001 = 1110
Popcorn Hack 3:
- The result of True or False and False is True since and has priority over or
Popcorn Hack 4:
- The result of Not True and False is False since not is evaluated first
Popcorn Hack 5:
- The result of True or False and not false is true because and/not are evaluated first
HW Hack 1:
Convert Decimal to Binary
def decimal_to_binary(decimal_number):
if decimal_number >= 0:
return bin(decimal_number)[2:] # Remove the '0b' prefix
else:
return '-' + bin(abs(decimal_number))[2:] # Handle negatives
Convert Binary to Decimal
def binary_to_decimal(binary_string):
if binary_string.startswith('-'):
return -int(binary_string[1:], 2)
else:
return int(binary_string, 2)
Test the functions
print("Decimal to Binary:")
print("10 →", decimal_to_binary(10))
print("-15 →", decimal_to_binary(-15))
print("\nBinary to Decimal:")
print("1010 →", binary_to_decimal("1010"))
print("-1111 →", binary_to_decimal("-1111"))
HW Hack 2:
import time
difficulty = input("Enter difficulty (easy, medium, hard): ").lower().strip()
Use and instead of or for correct logic
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)
Popcorn Hack 1:
Popcorn Hack 2:
Popcorn Hack 3:
Popcorn Hack 4:
Popcorn Hack 5:
HW Hack 1:
Convert Decimal to Binary
def decimal_to_binary(decimal_number):
if decimal_number >= 0:
return bin(decimal_number)[2:] # Remove the '0b' prefix
else:
return '-' + bin(abs(decimal_number))[2:] # Handle negatives
Convert Binary to Decimal
def binary_to_decimal(binary_string):
if binary_string.startswith('-'):
return -int(binary_string[1:], 2)
else:
return int(binary_string, 2)
Test the functions
print("Decimal to Binary:")
print("10 →", decimal_to_binary(10))
print("-15 →", decimal_to_binary(-15))
print("\nBinary to Decimal:")
print("1010 →", binary_to_decimal("1010"))
print("-1111 →", binary_to_decimal("-1111"))
HW Hack 2:
import time
difficulty = input("Enter difficulty (easy, medium, hard): ").lower().strip()
Use
andinstead oforfor correct logicwhile 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)