[Python] Python list numbers with selection

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I'm new to programming and currently learning python with reference book Python Programming Fundamentals. Here is one of the question I am dealing with:

    1: Request user to input a list of numbers.

    2: Then output those numbers which is in between 0 and 100.

    Following is my code:

    s = input("Please enter a list of numbers:") # request user to input a list of numbers
    lst = s.split() # Now lst is a list of strings.
    output = [] # Here is the beginning of the accumulator pattern

    for e in lst:
    if float(e) > 0 and float(e) < 100 : # inbetween 0 and 100
    output = output.append(float(e))
    else:
    output = output

    print("The number between 0 and 100 are ", output)


    And the error is:

    File "c:\Users\HKGGAIT001\Desktop\1.py", line 7, in <module>
    output = output.append(float(e))
    builtins.AttributeError: 'NoneType' object has no attribute 'append

    Continue reading...

Compartilhe esta Página