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

Create odd_or_even.py #2068

Open
wants to merge 4 commits into
base: master
from
Open

Create odd_or_even.py #2068

wants to merge 4 commits into from

Conversation

@vicky1999
Copy link
Contributor

vicky1999 commented Jun 3, 2020

Created odd_or_even.py to find whether a number is odd or even using bit manipulation.

For any odd number n: (n&1)=1
For any Even number n: (n&1)=0

vicky1999 added 3 commits Jun 3, 2020
@vicky1999
Copy link
Contributor Author

vicky1999 commented Jun 3, 2020

===================short test summary info==========================
FAILED bit_manipulation/odd_or_even.py::odd_or_even.odd_or_even
============ 1 failed, 594 passed, 776 warnings in 75.70s (0:01:15) ============
The command "pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=. ." exited with 1.

Copy link
Member

poyea left a comment

Thank you for the code. Please make changes to it to fix the failure.

bit_manipulation/odd_or_even.py Outdated Show resolved Hide resolved
return "Even"


if(__name__ == '__main__'):

This comment has been minimized.

Copy link
@poyea

poyea Jun 3, 2020

Member

Normally we don't write Python conditional like this.

if(n & 1 == 0):
return "Odd"
else:
return "Even"
Comment on lines 9 to 12

This comment has been minimized.

Copy link
@cclauss

cclauss Jun 3, 2020

Member
Suggested change
if(n & 1 == 0):
return "Odd"
else:
return "Even"
return "Odd" if n % 1 else "Even"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.