Write a program in python to print the sum of elements ending with 5 in a list of
integers.
For example if the list contains: -
12, 456 ,15 ,48, 275
The output of the following program will be 290
Answers
Answer:
lst = input ("Enter a list : ")
s = 0
for a in lst:
if a%5==0:
s += a
print ("Sum of numbers ending with 5 in the list",s)
else:
print ("No number ending with 5")
Concept:
Multiple items can be stored in a single variable using lists. Lists are declared using the square brackets. Lists are one of Python's four built-in data types for storing data collections.
Given:
A program in python to print the sum of elements ending with 5 in a list of
integers.
Find:
Write a program for the given statement.
Solution:
lst = [ ]
n = int(input("Enter number of elements : "))
print("Enter elements of the list: ")
for i in range(0, n):
ele = int(input())
lst.append(ele)
sum = 0
for a in lst:
if (a%10==5):
sum+= a
if(sum>0):
print("Sum of numbers ending with 5 in the lis is: ",sum)
else:
print("No number ending with 5")
![](https://hi-static.z-dn.net/files/d55/07f5d95eb3952576b3b82efedc01ed63.jpg)