How to find the the sum of the total negative numbers of the mass and find the numbers of the numbers between 0 and 1 Python



  • There's such a thing.

    a = [-1.1, -1, 0.1, 1, -2.1, -2, 0.2, 2, -3.1, -3, 0.3]
    

    from the cycle for (and no numpy) We need to get out of here.

    1. Total negative numbers: (-1)+(-2)+(-3) = -6
    2. Number of chips in range 0..1: 0.1, 0.2, 0.3 = 3

    I'm a newcomer. Python I can only find the sum of all the negative numbers, but I can't deny them.



  • Total negative numbers:

    b = sum(x for x in a if type(x) == int and x < 0)
    print(b)
    

    Total negative numbers c filter:

    d = sum(filter(lambda x:  isinstance(x, int) and x < 0 , a ))
    print(d)
    

    The numbers are 0-1.

    c = sum(1 for x in a if x<1 and x>0)
    print(c)
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2