create a picker that saves the selection to a new variable in python

One way to create a picker that saves the selection to a new variable in Python is to use a list of options and the input() function to prompt the user to select an option. Here is an example:

main.py
options = ["apple", "banana", "orange"]
selected_option = input("Select an option: " + ", ".join(options) + "\n")
114 chars
3 lines

In this code, we define a list of options (options) and use the join() method to combine them into a single string separated by commas. We then use the input() function to prompt the user to select an option and save their input to the variable selected_option.

Note that the input() function always returns a string, so if you need to use the selected option as an integer or float, you will need to convert it using the int() or float() function. Additionally, if you want to validate the user's input to ensure that it is one of the options in the list, you can use the in operator to check if the selected option is in the options list, and loop until a valid option is selected.

gistlibby LogSnag