Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python (retired) Inheritance Instance Methods

cody oberholtzer
cody oberholtzer
1,988 Points

Why does pressing enter at weapon input(without typing anything), pass 'if weapon_choice in "SAB": ' and selects bow?

Why does pressing enter at weapon input(without typing anything), pass 'if weapon_choice in "SAB": ' and selects bow?

Dongfeng Gu
Dongfeng Gu
12,281 Points

Hi Cody,

Can you describe your question more specifically? I would love to help your but I can't understand what you are saying.

Gu

1 Answer

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

That is interesting, it does.

Though instead if you change your first conditional statement to a list of letters like I put below, it shouldn't let you pass with an empty string.

def get_weapon(self):
    weapon_choice = input('Weapon ([S]word, [A]xe, [B]ow): ').lower()

    if weapon_choice in ['s','a','b']:
    #  the remaining code here 

From Docs

Empty strings are always considered to be a substring of any other string, so "" in "abc" will return True