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

Edit:

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

isWordGuessed("apple",<"a","e","i","k","p","r","s">)
python if-statement explanation
share
enhance this inquiry
monitor
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
4
add a comment |

4 answers 4


active oldest Votes
5
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.


re-publishing
improve this answer
monitor
reply Nov 13 "13 in ~ 20:23
*

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


re-superstructure
boost this price
follow
reply Nov 13 "13 at 20:22
*

Jack_of_All_TradesJack_of_All_Trades
9,8161414 gold badges5353 silver badges8282 bronze title
3
add a comment |
0
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


share
boost this prize
follow
reply Nov 13 "13 at 20:32
*

user2989435user2989435
1
add a comment |
0
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 )
re-publishing
boost this prize
follow
edited Nov 13 "13 at 20:52
reply Nov 13 "13 in ~ 20:43
dansalmodansalmo
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
send

Post together a guest


surname
email Required, however never shown


Post together a guest


name
email

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
Linked
1
"In" inspect not functioning in if Statement
associated
939
Python's equivalent of && (logical-and) in an if-statement
997
just how to catch and also print the full exception traceback without halting/exiting the program?
816
What is __future__ in Python offered for and how/when to usage it, and also how it works
1116
What is the difference in between null=True and also blank=True in Django?
1
else statement not printing. Supplied binary search
485
Why go "not(True) in " return False?
2
if statement without an else (when that seemingly demands one)
0
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.


lang-py
stack Overflow
products
agency
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.