Python Program to Print Sum of all Even Elements From Tuple

Python Program to Print Sum of all Even Elements From Tuple 


my_tuple=tuple(map(int,input("Enter tuple data items:").split()))

sum=0

for i in my_tuple:

    if isinstance(i,int):

        if i%2==0:

            print(i)

            sum=sum+i

print("The sum of tuple elements is:",sum)


Output:

Enter tuple data items:1 2 3 4 5 6 7 8 9 10

2

4

6

8

10

The sum of tuple elements is: 30

    

टिप्पणी पोस्ट करा

0 टिप्पण्या