Last active
January 8, 2024 21:28
-
-
Save Creveoolus/f20323bef760389762b0cd9f8540c482 to your computer and use it in GitHub Desktop.
Binary guessing game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code by: @Creveoolus | |
# HOW TO PLAY: https://www.youtube.com/watch?v=KCBz_qNLBZA | |
######### HINT ######### | |
# 010 - capitals | |
# 011 - lowercase | |
# 0011 - numbers | |
# 0010 - punctuation | |
import random | |
import time | |
import os | |
######### SETTINGS ######### | |
# c - capitals | |
# l - lowercase | |
# n - numbers | |
# p - punctuation | |
# w - words | |
MODE = '' | |
COUNT = 1 # Number of words to generate | |
WAIT = 2 # Time to wait before next round | |
CAPITALS = 'QWERTYUIOPASDFGHJKLZXCVBNM' | |
LOWERCASE = 'qwertyuiopasdfghjklzxcvbnm' | |
NUMBERS = '0123456789' | |
PUNCTUATION = '!.?' | |
def get_binary(mode=MODE): | |
word_set = [] | |
if 'c' in mode: | |
[word_set.append(x) for x in CAPITALS] | |
if 'l' in mode: | |
[word_set.append(x) for x in LOWERCASE] | |
if 'n' in mode: | |
[word_set.append(x) for x in NUMBERS] | |
if 'p' in mode: | |
[word_set.append(x) for x in PUNCTUATION] | |
if 'w' in mode: | |
try: | |
with open('words.txt', 'r', encoding='utf-8') as f: | |
words = f.readlines() | |
for word in words: | |
word_set.append(word.split('\n')[0]) | |
except FileNotFoundError: | |
raise Exception('Word file not found! Please create "words.txt" file and fill it with words OR remove the "w" mode.') | |
if not len(word_set): | |
return get_binary('clnp') | |
string = ' '.join([random.choice(word_set) for _ in range(COUNT)]) | |
final = ''.join(format(ord(x), 'b') for x in string) | |
return string, final | |
if '__main__' == __name__: | |
while True: | |
os.system('cls') | |
string, final = get_binary() | |
print('? Guess this binary ?') | |
# print(string) # SHOW ANSWER | |
print(final) | |
answer = input('>>> ') | |
if answer == string: | |
print('++++ CORRECT ++++') | |
else: | |
print(f'---- FALSE ---- ({string})') | |
time.sleep(WAIT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment