roster atbest
roster atbest

Reputation: 13

Python: Printing in if statements not running

I am making a python program that is an adventure game thing through a haunted house. One of the big things in it is a list called owned_items. This gets items which are represented by strings like, "box of matches" or "torch" appended to it when they find them in the house or are given to them at the start by random.choice. Sometimes, when they are presented with a situation, what choices they are given is dependent on whether they have a specific item or not.

My Code:

#bullets is the variable for pistol ammo. During my testing of this function, it is at 5 when it should start
bullets=5

owned_items=[]
ronald_items=["a glass bottle", "a pistol", "a torch", "a small glass of      oil", "a box of matches", "a can of spray paint", "a small knife", "a pair of      surgical gloves", "a blessed amulet"]
owned_items.append(random.choice(ronald_items))
ronald_items.remove(owned_items[0]
owned_items.append(random.choice(ronald_items))
ronald_items.remove(owned_items[1])


#This part is in the actual definition where the problem appears when it should run
def skeleton_choice():
    if "a glass bottle" in owned_items:
        print('type "glass bottle" to attack the skeletons with that bottle')
    if "a pistol" in owned_items and bullets>1:
        print('type "shoot" to try firing your pistol at the skeletons')
    if "a small knife" in owned_items:
        print('type "small knife" to use your small knife against the skeletons')
    if "a kitchen knife" in owned_items:
        print('Type "kitchen knife" to use your kitchen knife against the skeletons')
    if "a blessed amulet" in owned_items:
        print('Type "amulet" to use the blessed amulet to make this a fairer fight')
    print('Type "hands" to just fight the skeletons with your body')
    print('Type "run" to try and get away from the skeletons')

Even when I know that I have 3 of the items in these if statements, none of the prints show up. I'm using ifs rather than elifs and an else because I want it to show the print for everything they have, not just one. For example, if they have a glass bottle and a kitchen knife, I want it to give them the print statements for the bottle and the knife.

Upvotes: 0

Views: 83

Answers (2)

WholesomeGhost
WholesomeGhost

Reputation: 1121

You haven't called the function anywhere so that is why it doesn't work. Just add:

skeleton_choice()

line at the end. Also in the line

ronald_items.remove(owned_items[0]

you are missing a parentheses.

Upvotes: 1

Organis
Organis

Reputation: 7316

Your code works for me. That, after I added the call to skeleton_choice(). Might it be you just not calling it?

Upvotes: 0

Related Questions