I observe some things that can be improved (by my subjective opinion).
1. Get random item from list -> use random.choice. Benefits: only one item is needed, returns item (string) right away. Use sample when more than one random item is needed.
1. Get random item from list -> use random.choice. Benefits: only one item is needed, returns item (string) right away. Use sample when more than one random item is needed.
>>> pets = ['cat', 'dog', 'rat', 'gerbil', 'hamster', 'guiniepig', 'monkey', 'snake'] >>> random.choice(pets) 'dog'2. To construct string from different parts -> use f-strings. Benefits: better visual readability, no need for type conversion (if any). Requires 3.6 <= Python.
# Display ai result symbolically. >>> print(f'{active_pet} ({active_interior}, {active_exterior})\n')3. Open files -> use with context manager (as in buran examples). Benefits: file will be always properly and automagically closed, no need for close().
with open('data.txt', 'w') as f:4. Get only first row in file -> use built-in next(). Benefits: whole file content will not be read into memory/list to just get first row. Grab first row from existing fileobject and you are done.
with open('data.txt', 'r') as f: my_data = next(f).strip() # strips newline at the end, can be omitted.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.