[Solved] Can I use for-loop to get the same results? [closed]


for this code you cannot use input as a variable so I would rewrite it as this:

   choice = input("") #This will get a string that the user types.        

   if "stay" in choice: #This will execute the code below if the user has typed something with stay in it
        print dead("You were struck by lightning !")

    elif "wait" in choice and not(storm): #this will execute the code below if the user has typed something with the word wait in it and there is no storm(storm=False)
        print "The storm has stpped !"
        storm_halted=True

    elif "wait" in input and storm: #this will execute the code below if the user has typed something with the word wait in it and there is a storm (storm=True)
        print dead("You are lazy")
    elif "room" in input and storm : #this will execute the code below if the user has typed something with the word room in it and there is a storm (storm=True)
        gold ()
    else: #This code will execute if none of the above happen
        print dead("Type something")

as for the storm_halted = True the English for this would be: the storm has halted. Although the I think that you have accidentally inverted the not(storm) and storm in the elif’s by accident – Judging by the sense of the equivalents.

Hope this helps you understand. There is not really that much of another way to achieve this, and there is definitely no simpler way to do it.

1

solved Can I use for-loop to get the same results? [closed]