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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -