Computer Science, asked by duduk464dd, 6 months ago

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

Answered by Himanshu8715
13

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")

Answered by varshamittal029
3

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")

Attachments:
Similar questions