Detect Even/Odd Write a function with no parameters, even_or_odd() in Python Specifications:   read an integer from standard input return 0 if the integer is even, 1 if the integer is odd do not use a conditional ("if") statement, just use modular arithmetic (such as // or %) do not print the result, return it   HINT: What is the remainder when you divide an even number by 2?  What is the remainder when you divide an odd number by 2? REMINDER: DO NOT use prompts in your input statements for this problem.   For example: Test Input Result ans = even_or_odd() print(ans) 5 1 ans = even_or_odd() print(ans) -14 0 ans = even_or_odd() print(ans) 0 0 ans = even_or_odd() print(ans) 99 1

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.2: Returning A Single Value
Problem 3E
icon
Related questions
Question

Detect Even/Odd

Write a function with no parameters, even_or_odd() in Python

Specifications:

 

  • read an integer from standard input
  • return 0 if the integer is even, 1 if the integer is odd
  • do not use a conditional ("if") statement, just use modular arithmetic (such as // or %)
  • do not print the result, return it

 

HINT: What is the remainder when you divide an even number by 2?  What is the remainder when you divide an odd number by 2?

REMINDER: DO NOT use prompts in your input statements for this problem.

 

For example:

Test Input Result
ans = even_or_odd() print(ans) 5 1
ans = even_or_odd() print(ans) -14 0
ans = even_or_odd() print(ans) 0 0
ans = even_or_odd() print(ans) 99 1

 

Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning