-1

Here is the code:

delete=["del","delete","unistall","delall"]

action=(input("Please Select An Action To Do: "))

if action in delete:

    print("Ok,I will Delete whatever you wish")

Can I make it detect if one sentence contains any of the delete keywords,so make it do the action? e.x. :UserInput="delete menu",can it detect the delete keyword and do the right action?

Edit:Thanks for helping me out , the answer was to replace the if line with :

if any(word in action for word in delete):
3vil
  • 27
  • 7

2 Answers2

0

You should use the any() function instead. This way, you can test if any word in the delete list appears in the user-inputed sentence:

if any(word in action for word in delete):
    ...
Christian Dean
  • 22,138
  • 7
  • 54
  • 87
-1

You can split the input string to compare with delete list. so, the for example the code like blow delete=["del","delete","unistall","delall"]

action=(input("Please Select An Action To Do: "))

act_list =action.split(' ')

for act in act_list:
   for del in delete:
      if(act==del):
        print("Ok,I will Delete whatever you wish")

This code is just example, you can write better than above code.

xiangjian Wu
  • 116
  • 1
  • 1
  • 8