'removing numbers form list by python

Take 5 integer input from the user.

  1. Remove all numbers less than 9.

  2. Calculate the sum of remaining numbers

        python
        n = int(input("Enter number of elements : "))
        a = list(map(int,input("\nEnter the numbers : "). strip(). split()))
        for i in range(len(a)):
          if a[i]>9:
            a.remove(a[i])
            b=sum(a)
            print(b)
    


Solution 1:[1]

You can use this if you want to remove numbers less than 10 from the list and Calculate the sum of the remaining numbers

n = int(input("Enter number of elements : "))
a = list(map(int, input("\nEnter the numbers : ").strip().split()))

if len(a) == n:
    for num in a:
        if num < 9:
            a.remove(num)
    print('sum',sum(a))
else:
    print(f"You must enter {n} number") 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shima Fallah