search - How to make a the user input a command following a certain form in python? -
sorry gory title, can't work out called.
basically, want ask user "what do?" , have them able execute number of commands. example, "search fox" , program
if any(search in in list): print(list[search]) else: print(search + " not found.")
so basically, how can make code detect format "search [x]" , assign x variable search. also, if there name it, called? think me search next time.
the code below finds keyword removing command (here search for) input given user, way search query seperated.
def search(search_word): # search function here pass # input user user_input = raw_input("what do? ").lower() # make code easier reuse search_command = "search for" if len(user_input) > 0: if user_input.startswith(search_command): # use slices remove first part of input, , remove whitepsace search_word = user_input[len(search_command):].strip() search(search_word)
Comments
Post a Comment