Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question7_3_1: 0 < x < 5 -- "you should not use it" -- why? #176

Open
yarikoptic opened this issue Jan 19, 2019 · 3 comments
Open

question7_3_1: 0 < x < 5 -- "you should not use it" -- why? #176

yarikoptic opened this issue Jan 19, 2019 · 3 comments

Comments

@yarikoptic
Copy link
Contributor

yarikoptic commented Jan 19, 2019

it is about

condition-3-1: What is the correct Python expression for checking to see if a number stored in a variable x is between 0 and 5.
A. x > 0 and < 5
B. 0 < x < 5
C. x > 0 or x < 5
D. x > 0 and x < 5

and the answer is D, while B. having following feedback

This is tricky. Although most other programming languages do not allow this syntax, in Python, this syntax is allowed. However, you should not use it. Instead, make multiple comparisons by using and or or.

Since feedback is actually not giving an explanation on "Why" it shouldn't be used, and in my experience I do not frequently use this construct, I do not remember what could possibly discourage it. On the opposite, I found some (eg) somewhat encourage it as a neat Python feature making code closed to regular written math.

@dichharai
Copy link
Contributor

That's a good point. In my perspective, using logical operator is more of an implementation way of thinking than "dry" solving of Math expression. Moreover, using logical operator in expression is more readable, so more practiced?

Also looked up to see if there are any other articles/style guide that talks about to use Math expression or logical operators in Python expression, couldn't find.

Also the article (in confusing manner?) states that logical operator is used in expression when some variable is complex and rather not repeat.

screen shot 2019-01-29 at 10 37 18 am

So, the feedback for choice B may need a little tweak.

@dichharai
Copy link
Contributor

Made PR #195 for the issue.

@RustyDotson
Copy link
Contributor

It is usual to use x > 0 and x < 5 for checking if x is between the two numbers. However, 0 < x < 5 is still an equally viable solution to the problem meaning this question could be converted into a multiple answers problem where B and D are both correct answers. I'm currently working on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants