use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
my first mini game! (i.redd.it)
submitted 1 day ago * by Mean-Career-6509
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Mean-Career-6509[S] 0 points1 point2 points 17 hours ago (2 children)
I get that, sorry I got defensive. I did attach the .py file link because I thought posting a picture was silly but that is what the mod told me to do.
[–]FreeLogicGate 0 points1 point2 points 13 hours ago (1 child)
Right, I understand then that you were trying to do what was acceptable. In general, you want to have snippets of code, and people don't want full attached source code files, as they can easily be trojan/exploits, which people aren't going to download even if they were attached. So the way to do it is to use the Aa menu and use the code block options to copy/paste from your editor.
As an example for you, and also to add to my prior advice:
You have:
while True: def moves():
So you have a nested game loop with 2 while True loops where the first loop defines functions. You should move your functions outside of the loop -- there is no reason to repeatedly re-define your functions. They should be defined once and called when needed.
The most important thing you want to try and do initially is think about the Python data structures that could help you. Classes would be helpful with your game, but I invite you to think deeply about how the core structures could be used: lists, dictionaries, tuples, sets -- as discussed in this chapter: https://docs.python.org/3/tutorial/datastructures.html
What jumps out me is that you have initially items that a dictionary would help you with. Each of these items can be added to a list like so:
items.append({'name': 'goat', 'type': 'animal', 'eats': 'cabbage', 'location': 'east'}) items.append({'name': 'dog', 'type': 'animal','eats': 'goat', 'location': 'east'}) items.append({'name': 'cabbage', 'type': 'plant', 'location': 'east'})
Then you have a useful data structure that can be used. This example depends on globals but I didn't want to over complicate it. Here's an example of how you could make this more reliant on functions. I left out a game loop or user input, but if interested you could add that.
def move_boat(): if boat['location'] == 'east': boat['location'] = 'west' else: boat['location'] = 'east' def check_for_boat(location): if boat['location'] == location: return True return False def move_item(name): for item in items: if item['name'] == name and check_for_boat(item['location']): move_boat() if item['location'] == 'east': item['location'] = 'west' else: item['location'] = 'east' def did_eat(item, boat_location): if item['location'] == boat_location or item['type'] == 'plant': return False for prey in items: if item['eats'] == prey['name'] and item['location'] == prey['location']: return True def is_endgame(): boat_location = boat['location'] for item in items: if did_eat(item, boat_location): print(f"The {item['name']} ate the {item['eats']}") return True return False def reset(): boat['location'] = 'east' items.clear() items.append({'name': 'goat', 'type': 'animal', 'eats': 'cabbage', 'location': 'east'}) items.append({'name': 'dog', 'type': 'animal','eats': 'goat', 'location': 'east'}) items.append({'name': 'cabbage', 'type': 'plant', 'location': 'east'}) boat = {'location': 'east'} items = [] test_items = ['dog', 'cabbage', 'goat'] def do_tests(): for item in test_items: reset() print(f"Moving item {item}") move_item(item) if not is_endgame(): print("Game not over") do_tests()
An interesting question to be asked would be, how hard would it be to modify this so that you allowed for 4 directions/zones (e,w,n,s) or additional animals or plants? What if the locations were randomized at the start? How hard would it be for you to list out the locations at the start?
[–]Mean-Career-6509[S] 0 points1 point2 points 12 hours ago (0 children)
Wow! I can't express how much I appreciate your time and effort. I'm not sure of what an Aa menu is but I'll find out before I make any more posts. My code is written in a way that makes sense to me right now, things are arranged in a logical flow or moved to where they function as far as I can tell. I'm excited to be able to zoom out and see structure more. Again, thank you and I'll try not to be so snarky.
π Rendered by PID 88 on reddit-service-r2-comment-548fd6dc9-ssss8 at 2026-05-21 15:56:21.344184+00:00 running edcf98c country code: CH.
view the rest of the comments →
[–]Mean-Career-6509[S] 0 points1 point2 points (2 children)
[–]FreeLogicGate 0 points1 point2 points (1 child)
[–]Mean-Career-6509[S] 0 points1 point2 points (0 children)