Computer Science
Write a method EvenSum(NUMBERS) to add those values in the tuple of NUMBERS which are even.
Python
Python Functions
2 Likes
Answer
def EvenSum(NUMBERS):
even_sum = 0
for number in NUMBERS:
if number % 2 == 0:
even_sum += number
return even_sum
n = eval(input("Enter the tuple: "))
result = EvenSum(n)
print("The sum of even numbers in the tuple is:", result)
Output
Enter the tuple: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
The sum of even numbers in the tuple is: 30
Answered By
1 Like
Related Questions
Figure out the problem with the following code that may occur when it is run.
def recur(p): if p == 0: print ("##") else: recur(p) p = p - 1
Write a method in Python to find and display the prime numbers from 2 to N. The value of N should be passed as an argument to the method.
Write a function countNow(PLACES) in Python, that takes the dictionary, PLACES as an argument and displays the names (in uppercase) of the places whose names are longer than 5 characters. For example, Consider the following dictionary:
PLACES = {1: "Delhi", 2: "London", 3: "Paris", 4: "New York", 5:"Doha"}
The output should be:
LONDON
NEW YORKWrite a program using user-defined function to calculate and display average of all the elements in a user-defined tuple containing numbers.