Text Game - If statement based of input text - Python -


so, i'm making text based puzzle game using python programming class (we forced use python), instead of having user simple 1 or 2, want program detect if user has entered 'hesitate' or 'walk' exactly.

currently have determine amount of characters in user's input, makes possible them input anything.

#choice number1 def introchoice():     print("do 'hesitate? or 'walk forward")         def hesitate():             print()             print("you hesistate, startled sudden illumination of room. focusing on old man has turned you. gestures come closer. \n ''come in, come in, don't frightened. i'm frail old man'' says.")             print()         #         def walk():             print()             print("default")             print()         #currently determines input         inputvar = 5         #user input         choice = str(input())         #checks length         if len(choice) >= inputvar:             hesitate()         else:             if len(choice) <= inputvar:                 walk()             else:                 print("invalid input")  #intro choice def end #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# #clean #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# 

how can change if input walk or hesitate wont take input (in current code, walk not included in code yet). want like;

if input = "hesitate"    print("you hesitate") else:     if input = "walk"        print("you walk forward")     else:        print("invalid input") 

i can't figure out how can in python. searched everywhere.

is using console?

while true:     input = input("what do")     if input == "choice1":         print("consequence1")         break     if input == "choice2":         print("consequence2")         break     if input == "choice3":         print("consequence3")         break 

this not best way go doing this, achieves interperting asking.

really, answer lies in how loop.

in simple method, continously runs until breaks after being given valid input, more efficent solution argueably found using make-shift switch statement dictionary, example of discussed here. alternatively use more specific conditional in loop statement.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -