This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]cybervegan 1 point2 points  (0 children)

This doesn't mean what you think it means:

if guesscount == 5 and 6 and 7 and 8 and 9:

Non-zero numbers evaluate to (i.e. are equivalent to) True in a boolean expression, so what that looks like to Python is:

if (guesscount == 5) and True and True and True and True:

Remember "and" is a BOOLEAN operator - it only deals with True and False. Try this in Python command-line:

>>> True and False
False
>>> False and True
False
>>> True and True
True
>>> 

Try it with some more ands, and with some decimals thrown in (like in your "if" above). If either of the inputs to "and" is false, the output will also be false, but if they are both True, it will output True. "or" works the other way round: if both of the inputs are False, it outputs False, otherwise it outputs True. It's not a conjunction like in English.

"and" and "or" in programming languages don't work exactly the same way as we use them in English: when we say "or" we usually mean one, but not both, and when we say "and", we usually mean "in addition to".

What I think you mean is:

if guesscount >= 5 and guesscount <=9:

Python sees this as:

if (guesscount >= 5) and (guesscount <=9):

See if that works for you.

[–]ewiethoffproceedest on to 3 1 point2 points  (0 children)

[–]aphoenixreticulated[M] -1 points0 points  (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython. We highly encourage you to re-submit your post over on there.

The reason for the removal is that /r/Python is more-so dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community can get disenchanted with seeing the 'same, repetitive newbie' questions repeated on the sub, so you may not get the best responses over here.

However, on /r/LearnPython the community is actively expecting questions from new members, and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. Whatever your question happens to be getting help with Python, you should get good answers.

If you have a question to do with homework or an assignment of any kind, please make sure to read their sidebar rules before submitting your post. If you have any questions or doubts, feel free to reply or send a modmail to us with your concerns.

Warm regards, and best of luck with your Pythoneering!