-1

Okay so...

print("What do you wanna do?")

input1 = input()

if input1 == "Stab this guy" or input1 == "stab this guy":
     print("You stabbed that guy and killed him.")

elif input1 == "Punch this guy" or input1 == "punch this guy":
     print("You punched him...")

I want to try and create a loop with these complex inputs, so when you enter an input that is still complex but isn't mentioned I want it to print something like "Sorry didn't catch that" so they have to repeat a different input that would be covered in the input list until they say the right input.

TOASTED PIE
  • 37
  • 1
  • 8
  • You are looking at a `while` loop, e.g. `while True:` will loop forever unless you explicitly `break` out of the loop. – AChampion Apr 05 '16 at 01:03
  • However in a while loop you cant have complex inputs, or is this untrue, because i have tried this way but i couldn't figure out a way to work with complex inputs – TOASTED PIE Apr 05 '16 at 01:08

1 Answers1

2

To build on what you have already:

print("What do you wanna do?")

input1 = input()

complex_inputs = ["stab this guy", "punch this guy"]

while input1.lower() not in complex_inputs:
    print("Sorry didn't catch that")
    print("What do you wanna do?")
    input1 = input()

if input1 == "Stab this guy" or input1 == "stab this guy":
    print("You stabbed that guy and killed him.")

elif input1 == "Punch this guy" or input1 == "punch this guy":
    print("You punched him...")

Edit:

To also handle keywords this is one idea:

print("What do you wanna do?")

input1 = input()

complex_inputs = ["stab this guy", "punch this guy"]

actions_list = [action for actions in complex_inputs for action in actions.split()]

while input1.lower() not in (actions_list or complex_inputs):
    print("Sorry didn't catch that")
    print("What do you wanna do?")
    input1 = input()

if input1.lower() in "stab this guy":
    print("You stabbed that guy and killed him.")

elif (input1.lower() in "punch this guy"):
    print("You punched him...")
  • This doesn't work. If you have an uppercase letter E.g. "Punch this guy", compared to "punch this guy" only "punch this guy" would work, therefore not being able to vary in your inputs which is exactly what I want, for my users to be able to experience freedom in their inputs. – TOASTED PIE Apr 05 '16 at 01:23
  • You should define `complex_inputs` with all-lowercase strings. Your check would be `while input1.lower() not in complex_inputs:` – zondo Apr 05 '16 at 01:27
  • good point, thanks for catching and pointing that out – chickity china chinese chicken Apr 05 '16 at 01:33
  • To further complicate situations would there be a possible way to add in more than just two inputs, so for the Punch this guy one would it be possible to be able to add in just "Punch"? – TOASTED PIE Apr 05 '16 at 01:37
  • Sure, just add more inputs into the complex_inputs list like so: `complex_inputs = ["stab this guy", "punch this guy", 'punch']` and if you want a corresponding response for it, add it below as you did for the others: `elif input1.lower() == "punch": print("A Punch...")` – chickity china chinese chicken Apr 05 '16 at 01:38
  • Yes but could i get "Punch" to be able to link in with "Punch this guy", so instead of creating a whole new line for an input that means the same thing would it be possible to have two different inputs print the same line? – TOASTED PIE Apr 05 '16 at 01:44
  • You sure can. That one took me a bit to figure out (-: I'll add it as another answer, let me know if it's not what you have in mind. – chickity china chinese chicken Apr 05 '16 at 05:35