Lecture
Coding Quiz - Determine Odd/Even
In this quiz, you will write a function using the while loop and lists to determine whether each number in a given list of integers is odd or even. Based on this, the function will return a new list containing the strings "Odd" or "Even".
The solution function iterates over each element in the input list and adds "Odd" if the element is odd or "Even" if the element is even to a new list, and then returns it.
Parameter Format
def solution(numbers): # Write your code here return
Constraints
-
The input list contains only integers.
-
The list is not empty and contains at least one element.
Example
-
Input:
[1, 2, 3, 4, 5] -
Output:
["Odd", "Even", "Odd", "Even", "Odd"]
Lessons in this chapter Β· While Loops and List Comprehensions
- 1. How to Execute a Loop While a Given Condition is True
- 2. Controlling Logic Flow Inside Loops
- 3. Using While Loops with Lists
- 4. Multiple-choice quiz
- 5. Calculating Minimum, Maximum, and Sum
- 6. How to Reverse the Order of Objects
- 7. Iterating Over Elements of an Iterable
- 8. Iterating Over Key-Value Pairs with the items() Function
- 9. Simplifying Lists with List Comprehensions
- 10. Using the join() Function to Concatenate Strings
- 11. Differences Between Iterables and Iterators
- 12. Coding Quiz - Determine Odd/Even
- 13. Multiple-choice quiz
- 14. Fill-in-the-blank quiz
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help