Python Forum
Identifying only specific words in a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Identifying only specific words in a string
#3
Thanks for your help j.crater!

eventually what ended up working was this:
action = input("> ")
while True:
    if "fire" in action:
        print('You attack the alien ship!')
        break
    elif "attack" in action:
        print('You attack the alien ship!')
        break
    elif "shields" in action:
        print('You raise your shields!')
        break
    elif "defense" in action:
        print('You raise your shields!')
        break
    elif "hail" in action:
        print('You try to hail the alien ship!')
        break
    elif "communicate" in action:
        print('You try to hail the alien ship!')
        break
    else:
        print("Unknown action, try again.\n")
        action = input("> ")
There's probably a simpler way to do it, but this is the only way I could figure out right now.
Reply


Messages In This Thread
RE: Identifying only specific words in a string - by GilbyScarChest - Aug-08-2018, 03:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pulling Specifics Words/Numbers from String bigpapa 2 901 May-01-2023, 07:22 PM
Last Post: bigpapa
  Identifying if the program I have is python and then decompiling jpnyc 7 2,581 Jun-02-2022, 10:16 PM
Last Post: jpnyc
  Identifying keywords in text drchips 6 132,096 Mar-29-2022, 12:32 PM
Last Post: snippsat
  trying to put a a filter on identifying a straight CompleteNewb 1 1,752 Dec-01-2021, 11:11 PM
Last Post: CompleteNewb
  Extract a string between 2 words from a text file OscarBoots 2 1,996 Nov-02-2021, 08:50 AM
Last Post: ibreeden
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 2,439 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 3,009 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  How to extract specific key value pair from string? aditi06 0 2,674 Apr-15-2021, 06:26 PM
Last Post: aditi06
  Replacing a words' letters in a string cananb 2 3,624 Dec-01-2020, 06:33 PM
Last Post: perfringo
  Printing string at specific position on terminal - not showing __Mathieu__ 1 2,534 Sep-07-2020, 10:32 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020