Python function not returning anything -
def equip(x): global bag_sword global bag_chest global bag_gloves global bag_helmet while x == "iron sword" , "iron sword" in bag: if bag_sword: print "you can't have 2 weapons equipped!" x = "" print "\nyou equip iron sword.\n" bag.remove("iron sword") bag_sword.append("iron sword")
when run first time, works fine, when run second time nothing happens.
bag_sword
list
test code:
bag.append("iron sword") if input1[:5] == "equip": print input1[:5] equip(input1[6:]) print input1[6:] type console 'equip iron sword'
i've tried using variable in place of input[]
(it isn't syntax)
here how can make function work described:
bag_sword = [] def equip(x): global bag_sword if x == "iron sword": if "iron sword" in bag_sword: print "you can't have 2 weapons equipped!" else: bag_sword.append("iron sword") print bag_sword # prints "[]". equip("iron sword") # prints nothing. puts string "iron sword" in bag_sword. print bag_sword # prints "['iron sword']". equip("iron sword") # prints "you can't have 2 weapons equipped!". bag_sword unchanged.
Comments
Post a Comment