Skip to content

Instantly share code, notes, and snippets.

@averwhy
Created February 7, 2022 20:00
Show Gist options
  • Save averwhy/a2041c729cc93ad3ebd30a05c531e2b2 to your computer and use it in GitHub Desktop.
Save averwhy/a2041c729cc93ad3ebd30a05c531e2b2 to your computer and use it in GitHub Desktop.
TikTok Button Thing (unfinished)
import random
import yaml
from os.path import exists
class Config:
def __init__(self):
pass
def load(self, filename="button_stats"):
"""Loads the config file. Creates it if it doesnt exist. Returns the opened file object."""
filename = f"{filename}.yml"
try: open(filename, "x")
except OSError: return self.create()
with open(f'{filename}.yml', 'r') as f:
return yaml.safe_load(f)
def create(self):
"""Creates the configuration and fills in the default values. Returns the opened file object."""
pass
def reset(self):
"""Resets the configuration, assuming it exists. Returns nothing."""
pass
def update(self, data, close=False):
"""Updates the YAML file. Optional argument can close it after updating. Returns nothing."""
pass
class Button:
def __init__(self):
self.presses = 0
self.reward = 25000
def press(self):
"""Returns True if you turn into a turtle, False if not."""
self.presses += 1
if random.randint(1, 100) == 1: return True
else: return False
done = False
c = Config().load()
a = Button()
print("There is a button in front of you. When you press it, you get 25,000 USD. However, it has a 1 percent chance of tunring you into a small turtle.")
while not done:
print(f"You've pressed it {a.presses} times, and have gained ${a.presses * a.reward}.")
print("Press the button? [Y / N]")
try:
yORn = input(">")
if yORn.strip() == "N": done = True; break
except Exception: print("You did it wrong, try again"); continue
if a.press():
print(f"You turned into a turtle after {a.presses} presses!")
__import__("time").sleep(3)
break
else: print("You gained $25,000."); continue
c.update(close=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment