Write definition of a method/function DoubletheOdd(Nums) to add and display twice of odd values from the list of Numbers.
For example: If the Nums contains [25,24,35,20,32,41] The function should display
Twice of Odd Sum: 202
Answers
Answer:
Program to display twice of odd values from the list of Numbers.
Question : Write definition of a method/function DoubletheOdd(Nums) to add and display twice of odd values from the list of Numbers.
Explanation:
From the above question,
They have given :
For example: If the Nums contains [25,24,35,20,32,41] The function should display
Twice of Odd Sum: 202
PROGRAM
Function DoubletheOdd(Nums):
# Create a new empty list.
DoubleOddNums = []
# Iterate through numbers in the input list.
for num in Nums:
# Checks if number is odd.
if num % 2 != 0:
# Append twice of the odd number in the new list.
DoubleOddNums.append(num * 2)
# Return the new list consisting of doubled odd numbers.
return DoubleOddNums
Function DoubletheOdd(Nums)
{
// Create a new empty list to store the doubled values
var doubledOddNums = [];
// Iterate through the list of numbers
for (let i = 0; i < Nums.length ; i++) {
// Check if the current number is odd
if (Nums[i] % 2 !== 0) {
// If so, double the number and add it to the new list
doubledOddNums.push(Nums[i] * 2);
}
}
// Return the new list of doubled odd numbers
return doubledOddNums;
}
For more such related questions : https://brainly.in/question/49333061
#SPJ1