99. Problem to round every number in a given list of numbers

In this Python list program, we will take a user input as a list and round every number in a given list of numbers, and print the total sum of the list with the help of the below-given steps.

Round every number in list:

Steps to solve the program
  1. Take a list having positive, negative, and float numbers as input and create an empty list.
  2. Use for loop to iterate over each value of the list and round it by using the round() function.
  3. Add the rounded number to the empty list.
  4. Calculate the sum of the new list.
  5. Print the sum.
				
					#Input list
list1 = [22.4, 4.0, -16.22, -9.1, 11.0, -12.22, 14.2, -5.2, 17.5]
list2 = []

for value in list1:
    list2.append(round(value))
    
#Printing output
total = (sum(list2))
print(total)
				
			

Output :

				
					27
				
			

Related Articles

Python Program to get the Median of all the elements from the list.

Python Program to get the Standard deviation of the list element.

Python program to convert all numbers to binary format from a given list.

Python program to convert all the numbers into Roman numbers from the given list.

Python program to calculate the square of each number from the given list.

Python program to combine two lists.

 

 

 

Decode a run-length encoded list

Leave a Comment