Computer Science, asked by atahrv, 4 months ago

Write a program in Python to create a list with 5 integer items and display the following :
(a) The value(s) ending with 2
(b) Maximum and Minimum value from the list.
(c) Sum of all the odd values

Answers

Answered by pranavsingh123
5

Explanation:

Python program to find sum of elements in list

total = 0

# creating a list

list1 = [11, 5, 17, 18, 23]

# Iterate each element in list

# and add them in variale total

for ele in range(0, len(list1)):

total = total + list1[ele]

# printing total value

print("Sum of all elements in given list: ", total)

Answered by Piyani1716
1

Answer:

Python program to find sum of elements in listLast Updated: 24-11-2020

Given a list of numbers, write a Python program to find the sum of all the elements in the list.

Example: 

 

Input: [12, 15, 3, 10] Output: 40 Input: [17, 5, 3, 5] Output: 30

Example #1: 

 

Python3

# Python program to find sum of elements in list

total = 0

 

# creating a list

list1 = [11, 5, 17, 18, 23]

 

# Iterate each element in list

# and add them in variale total

for ele in range(0, len(list1)):

    total = total + list1[ele]

 

# printing total value

print("Sum of all elements in given list: ", total)

Output: 

 

Sum of all elements in given list: 74

  

Example #2 : Using while() loop 

 

Python3

# Python program to find sum of elements in list

total = 0

ele = 0

 

# creating a list

list1 = [11, 5, 17, 18, 23]

 

# Iterate each element in list

# and add them in variale total

while(ele < len(list1)):

    total = total + list1[ele]

    ele += 1

     

# printing total value

print("Sum of all elements in given list: ", total)

Similar questions