How do I make a selection in python?
So, I'm making a story for a game. I need a choice function for it. It's supposed to be some like an arrow pointing to options. Like
And of course the arrow.
You could probably do something like that with tkinter or pygame. If you are asking like text RPGs then you could definitely do something like:
ask = input("1. Go to John\n2. Be sad :(\n") if int(ask) == 1: print("option one") elif int(ask) == 2: print("option 2")
which would ask the user
Option 1: Go to John Option 2: Be sad :(
Or you could change it to be more like
Do you walk into the room? (Y/n)
Or if you want it to be chunkier but less likely to mess up on the user end and throw some weird error like:
Traceback (most recent call last): File "main.py", line 13, in <module> if int(ask) == 1: ValueError: invalid literal for int() with base 10: '35ejaf'
def ask1(): ask = input("1. Go to John\n2. Be sad :(\n") try: if int(ask) == 1: print("option one") elif int(ask) == 2: print("option 2") else: ask1() except: ask1() ask1()
If you prefer that. Hope this could have of helped.