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 trialcody oberholtzer
1,988 PointsWhy 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?
1 Answer
Chris Howell
Python Web Development Techdegree Graduate 49,702 PointsThat 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
Dongfeng Gu
12,281 PointsDongfeng Gu
12,281 PointsHi Cody,
Can you describe your question more specifically? I would love to help your but I can't understand what you are saying.
Gu