I am creating a straightforward program because that a homework problem and also It seems to it is in skipping mine if statement. I have actually looked at other questions posed, and the difficulties there do not it seems ~ to it is in my problem so i am hope you can help.

You are watching: Which statement about printing is false?

def isWordGuessed(secretWord, lettersGuessed):if lettersGuessed == <>: return Falseelse: for ns in lettersGuessed: if i in secretWord == False: return False else: if ns == lettersGuessed<-1>: return TrueWhen I location in some print attributes to watch what it is doing, it completely skips

if ns in secretWord == False:I have placed right above this line

print i in secretWordand it will print out the correct Boolean, yet even once it prints False, the still skips the if statement. Ns feel choose I must be overlooking something quite basic, but what it is ns can"t it seems to be ~ to figure out, therefore any help would it is in appreciated. Thanks


Here is an instance of a contact to this role with inputs

python if-statement explanation
enhance this inquiry
edited Nov 13 "13 in ~ 20:26


user2357112 support Monica
221k2222 gold badges339339 silver badges411411 bronze title
request Nov 13 "13 at 20:13

El SergioEl Sergio
3377 bronze title
add a comment |

4 answers 4

active oldest Votes
if ns in secretWord == False:This doesn"t carry out what friend think it does. If you want this course to it is in taken once i isn"t in secretWord, you want

if i no in secretWord:What you have actually does a chained comparison. First, it checks

i in secretWordIf that"s true, it climate checks

secretWord == FalseIf that"s true (which the won"t be), it then takes the if path.

improve this answer
reply Nov 13 "13 in ~ 20:23

user2357112 support Monicauser2357112 support Monica
221k2222 yellow badges339339 silver- badges411411 bronze badges
include a comment |
Replace if ns in secretWord == False: through if i no in secretWord

boost this price
reply Nov 13 "13 at 20:22

9,8161414 gold badges5353 silver badges8282 bronze title
add a comment |
Wouldnt it be the same just doing:


def isWordGuessed(secretWord, lettersGuessed):if not lettersGuessed: return Falsefor ns in lettersGuessed: if i no in secretWord: return Falsereturn TrueWhat her doing is dubbed chained comparisons.

Edit: mine bad, also late

BR Daniel

boost this prize
reply Nov 13 "13 at 20:32

add a comment |
The other answers define the error in the code well, but you have the right to simplify your password a bit like this:

def isWordGuessed(secretWord, lettersGuessed): for ns in lettersGuessed or <"_">: # supplies <"_"> when lettersGuessed = <> if not i in secretWord: return False return TrueYou can do likewise do this with a generator expression and also all():

def isWordGuessed(secretWord, lettersGuessed): return all( or )
boost this prize
edited Nov 13 "13 at 20:52
reply Nov 13 "13 in ~ 20:43
10.6k55 yellow badges5353 silver badges4949 bronze badges
add a comment |

her Answer

many thanks for contributing an answer to stack Overflow!

Please be certain to answer the question. Provide details and share your research!

But avoid

Asking because that help, clarification, or responding to other answers.Making statements based upon opinion; back them increase with referrals or an individual experience.

To learn more, see our advice on writing an excellent answers.

See more: 1 Litre Is Equal To How Many Grams ? Convert Litre To Grams

Draft saved
Draft discarded

Sign up or log in in

sign up utilizing Google
authorize up utilizing Facebook
authorize up using Email and also Password

Post together a guest

email Required, however never shown

Post together a guest


Required, yet never shown

article Your price Discard

By click “Post your Answer”, friend agree to our terms of service, privacy policy and also cookie policy

Not the prize you're feather for? Browse various other questions tagged python if-statement declaration or questioning your own question.

The Overflow Blog
Featured top top Meta
"In" inspect not functioning in if Statement
Python's equivalent of && (logical-and) in an if-statement
just how to catch and also print the full exception traceback without halting/exiting the program?
What is __future__ in Python offered for and how/when to usage it, and also how it works
What is the difference in between null=True and also blank=True in Django?
else statement not printing. Supplied binary search
Why go "not(True) in " return False?
if statement without an else (when that seemingly demands one)
problem with BMI calculation regime - if else and calculation errors in dev C++
hot Network concerns more hot concerns

inquiry feed
subscribe to RSS
inquiry feed To subscribe to this RSS feed, copy and also paste this URL right into your RSS reader.

stack Overflow
stack Exchange Network
site design / logo design © 2021 ridge Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.10.5.40381

Stack Overflow works ideal with JavaScript enabled

her privacy

By click “Accept every cookies”, friend agree stack Exchange can store cookies on your machine and disclose info in accordance through our Cookie Policy.