I'm writing a tool which users can select multiple choices at once. Whilst I can't provide the actual content, I've replicated it with fruit. I'm replicating some functionality from Nikto where it allows different flags like "-mutation abcd".
for example here we have three fruits:
1- apple
2- orange
3- kiwi
I wanna let users to type "12" or "appleorange" or "21" or "orangeapple" for selecting apple and orange, or "123" or "appleorangekiwi" or vice versa to select apple, orange and kiwi and etc.
Assume that there are more than 3 choices, so it would be pain in the neck if I want to write elif statement for all multiple selections. How can I make my code simpler and shorter?
Here is my code:
fruits_ls = []
def add_fruits():
while True:
print("choose your favorite fruits:\n"
"1- apple\n"
"2- orange\n"
"3- kiwi\n"
"4- exit\n")
my_fruits = input()
if my_fruits == str(1) or my_fruits == "apple":
fruits_ls.append("Apple")
elif my_fruits == str(2) or my_fruits == "orange":
fruits_ls.append("Orange")
elif my_fruits == str(3) or my_fruits == "kiwi":
fruits_ls.append("Kiwi")
elif my_fruits == str(12) or my_fruits == "appleorange" or my_fruits == str(21) or my_fruits == "orangeapple":
fruits_ls.append("Apple")
fruits_ls.append("Orange")
elif my_fruits == str(13) or my_fruits == "applekiwi" or my_fruits == str(31) or my_fruits == "kiwiapple":
fruits_ls.append("Apple")
fruits_ls.append("Kiwi")
elif my_fruits == str(23) or my_fruits == "orangekiwi" or my_fruits == str(32) or my_fruits == "kiwiorange":
fruits_ls.append("Orange")
fruits_ls.append("Kiwi")
elif my_fruits == str(4) or my_fruits == "exit":
break
add_fruits()
print(fruits_ls)
argparse
? Idk if it does this, but have you checked? \$\endgroup\$