python - Text based game input -
i might being stupid, cant figure out. i'm making text based game , in order simulate character movement in different scenarios, have used following code:
import random north = ("there path north. ") south = ("there path south. ") east = ("there path east. ") west = ("there path west. ") nsew = [north, south, east, west] print ("you find in woodland clearing. ") print (random.choice(nsew)) print (random.choice(nsew)) print (random.choice(nsew)) print (random.choice(nsew)) direction = input("which way go? ")
this should print 4 random items list, does. want able like:
if direction == ("north"): print ("you decide go north.")
but if statement each one, if user types "east" program respond "you decide go east"
thanks
import random paths = [] tiaptt = "there path " nsew = ["north", "south", "east", "west"] amount = random.randrange(1,4) path in random.sample(nsew,amount): print tiaptt+path paths.append(path.lower()) direction = raw_input("which way go? ") try: index = paths.index(direction.lower()) print "you have chosen go %s"%paths[index] except: print "you have chosen wrong direction"
hope helps. works in python 2.7, if use 3+ might want change raw_input input. , put () around prints.
print ("you have chosen go %s"%paths[index])
Comments
Post a Comment