Skip to content
Question

Q.Write definition of a method/function AddOddEven(VALUES) to display sum of odd and even values separately from the list of VALUES. For example : If the VALUES contain [15, 26, 37, 10, 22, 13] The function should display Even Sum: 58 Odd Sum: 65

(OR)
Write definition of a method/function HowMany(ID,Val) to count and display number of times the value of Val is present in the list ID. For example : If the ID contains [115,122,137,110,122,113] and Val contains 122 The function should display 122 found 2 Times
CBSECBSE Class XII Board 2019Subjective· 3mImportance★★★★★est
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Part (a): AddOddEven prints Even Sum: 58 and Odd Sum: 65 for [15, 26, 37, 10, 22, 13].

Part (b): HowMany prints "122 found 2 Times" for the given list and value.

Part (a)

We need the sum of even numbers and the sum of odd numbers, displayed separately. Keep two accumulators starting at 0. For each element, num % 2 == 0 is true for even numbers, so add it to even_sum; otherwise add it to odd_sum. The question says display, so we use print() (not return).

def AddOddEven(VALUES):
    even_sum = 0
    odd_sum = 0
    for num in VALUES:
        if num % 2 == 0:
            even_sum += num
        else:
            odd_sum += num
    print("Even Sum:", even_sum)
    print("Odd Sum:", odd_sum)

AddOddEven([15, 26, 37, 10, 22, 13])

For [15, 26, 37, 10, 22, 13]: evens are 26, 10, 22 (sum 58); odds are 15, 37, 13 (sum 65). Output:

Even Sum: 58
Odd Sum: 65 …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.