Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
2

How do I make a selection in python?

MilescOde
MilescOde

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

  • option1
  • option2.
    And of course the arrow.
1 year ago

Voters

Comments

TopNew
2
JonDoeBeep
JonDoeBeep

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'

Do:

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.
TLDR:
Code above.

1 year ago
1
MilescOde
MilescOde

@JonDoeBeep
Thanks for the idea!

1 year ago
1
MilescOde
MilescOde

I went for like
def go():
ask = input("...

1 year ago
Load more