- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check whether product of 'n' numbers is even or odd in Python
Suppose we have an array nums. We have to check whether the product of these numbers is even or odd.
So, if the input is like nums = [5,7,4,2,6], then the output will be Even, as the multiplication is 1680 and this is even.
To solve this, we will follow these steps −
- for i in range 0 to size of nums - 1, do
- if nums[i] is even, then
- return "Even"
- if nums[i] is even, then
- return "Odd"
Let us see the following implementation to get better understanding −
Example Code
def solve(nums): for i in range(len(nums)): if not nums[i] & 1: return "Even" return "Odd" nums = [5,7,4,2,6] print(solve(nums))
Input
[5,7,4,2,6]
Output
Even
Advertisements