Python列出带有选择的数字

Python列出带有选择的数字,python,Python,我是编程新手,目前正在通过参考书《python编程基础知识》学习python。以下是我正在处理的一个问题: 1:请求用户输入数字列表 2:然后输出介于0和100之间的数字 以下是我的代码: 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

我是编程新手,目前正在通过参考书《python编程基础知识》学习python。以下是我正在处理的一个问题:

1:请求用户输入数字列表

2:然后输出介于0和100之间的数字

以下是我的代码:

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)
s=input(“请输入数字列表:”)#请求用户输入数字列表
lst=s.split()#现在lst是字符串列表。
output=[]#这里是累加器模式的开始
对于lst中的e:
如果浮动(e)>0且浮动(e)<100:#介于0和100之间
output=output.append(float(e))
其他:
输出=输出
打印(“0到100之间的数字为”,输出)
错误是:

File "c:\Users\HKGGAIT001\Desktop\1.py", line 7, in <module>
  output = output.append(float(e))
builtins.AttributeError: 'NoneType' object has no attribute 'append 
文件“c:\Users\HKGGAIT001\Desktop\1.py”,第7行,在
output=output.append(float(e))
builtins.AttributeError:“非类型”对象没有“附加”属性

假设您使用的是
Python2.x
,那么您当前的代码有几个问题

  • 使用
    input
    会导致Python尝试评估用户输入,这会导致问题,因为您希望他们输入一个数字列表
    raw_input
    只提供用户输入的内容,而不尝试解析它

  • list.append
    已就位,这意味着函数调用的副作用只是在调用它的对象上执行append,而不是返回新对象

  • 试试这个:

    s = raw_input("Please enter a list of numbers: ") 
    lst = s.split()
    output = []
    
    for e in lst:
        if float(e) > 0 and float(e) < 100 :     # inbetween 0 and 100
             output.append(float(e))
    
    print("The number between 0 and 100 are ", output)
    
    s=原始输入(“请输入数字列表:”)
    lst=s.split()
    输出=[]
    对于lst中的e:
    如果浮动(e)>0且浮动(e)<100:#介于0和100之间
    输出追加(浮点(e))
    打印(“0到100之间的数字为”,输出)
    
    假设您使用的是
    Python2.x
    ,那么您当前的代码有几个问题

  • 使用
    input
    会导致Python尝试评估用户输入,这会导致问题,因为您希望他们输入一个数字列表
    raw_input
    只提供用户输入的内容,而不尝试解析它

  • list.append
    已就位,这意味着函数调用的副作用只是在调用它的对象上执行append,而不是返回新对象

  • 试试这个:

    s = raw_input("Please enter a list of numbers: ") 
    lst = s.split()
    output = []
    
    for e in lst:
        if float(e) > 0 and float(e) < 100 :     # inbetween 0 and 100
             output.append(float(e))
    
    print("The number between 0 and 100 are ", output)
    
    s=原始输入(“请输入数字列表:”)
    lst=s.split()
    输出=[]
    对于lst中的e:
    如果浮动(e)>0且浮动(e)<100:#介于0和100之间
    输出追加(浮点(e))
    打印(“0到100之间的数字为”,输出)
    
    假设您使用的是
    Python2.x
    ,那么您当前的代码有几个问题

  • 使用
    input
    会导致Python尝试评估用户输入,这会导致问题,因为您希望他们输入一个数字列表
    raw_input
    只提供用户输入的内容,而不尝试解析它

  • list.append
    已就位,这意味着函数调用的副作用只是在调用它的对象上执行append,而不是返回新对象

  • 试试这个:

    s = raw_input("Please enter a list of numbers: ") 
    lst = s.split()
    output = []
    
    for e in lst:
        if float(e) > 0 and float(e) < 100 :     # inbetween 0 and 100
             output.append(float(e))
    
    print("The number between 0 and 100 are ", output)
    
    s=原始输入(“请输入数字列表:”)
    lst=s.split()
    输出=[]
    对于lst中的e:
    如果浮动(e)>0且浮动(e)<100:#介于0和100之间
    输出追加(浮点(e))
    打印(“0到100之间的数字为”,输出)
    
    假设您使用的是
    Python2.x
    ,那么您当前的代码有几个问题

  • 使用
    input
    会导致Python尝试评估用户输入,这会导致问题,因为您希望他们输入一个数字列表
    raw_input
    只提供用户输入的内容,而不尝试解析它

  • list.append
    已就位,这意味着函数调用的副作用只是在调用它的对象上执行append,而不是返回新对象

  • 试试这个:

    s = raw_input("Please enter a list of numbers: ") 
    lst = s.split()
    output = []
    
    for e in lst:
        if float(e) > 0 and float(e) < 100 :     # inbetween 0 and 100
             output.append(float(e))
    
    print("The number between 0 and 100 are ", output)
    
    s=原始输入(“请输入数字列表:”)
    lst=s.split()
    输出=[]
    对于lst中的e:
    如果浮动(e)>0且浮动(e)<100:#介于0和100之间
    输出追加(浮点(e))
    打印(“0到100之间的数字为”,输出)
    
    s=input(“请输入数字列表:”)
    输出=[如果每个>0.0且每个<100.0,则每个在s中]
    打印(“0到100之间的数字为”,输出)
    
    s=input(“请输入数字列表:”)
    输出=[如果每个>0.0且每个<100.0,则每个在s中]
    打印(“0到100之间的数字为”,输出)
    
    s=input(“请输入数字列表:”)
    输出=[如果每个>0.0且每个<100.0,则每个在s中]
    打印(“0到100之间的数字为”,输出)
    
    s=input(“请输入数字列表:”)
    输出=[如果每个>0.0且每个<100.0,则每个在s中]
    打印(“0到100之间的数字为”,输出)
    
    假设您正在使用Python3(因为.split()不太可能在Python2中成功)

    这部分没问题

    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 0 < float(e) < 100 :     # inbetween 0 and 100
             output.append(float(e))
    
    但是现在我们需要使用
    float(e)
    两次

    我们可以使用另一个来使
    lst
    已经成为
    float

    s = input("Please enter a list of numbers:") # request user to input a list of numbers
    lst = [float(e) for e in s.split()]          # Now lst is a list of floats.
    output = [e for e in lst if 0 < e < 100]
    

    假设您正在使用Python3(因为.split()在Python2中不太可能成功)

    这部分没问题

    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 0 < float(e) < 100 :     # inbetween 0 and 100
             output.append(float(e))
    
    但是现在我们需要使用
    float(e)
    两次

    我们可以使用另一个来使
    lst
    已经成为
    float

    s = input("Please enter a list of numbers:") # request user to input a list of numbers
    lst = [float(e) for e in s.split()]          # Now lst is a list of floats.
    output = [e for e in lst if 0 < e < 100]
    

    假设您正在使用Python3(因为.split()在Python2中不太可能成功)

    这部分没问题

    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 0 < float(e) < 100 :     # inbetween 0 and 100
             output.append(float(e))
    
    但是现在我们需要使用
    float(e)
    两次

    我们可以使用另一个来使
    lst
    已经成为
    float

    s = input("Please enter a list of numbers:") # request user to input a list of numbers
    lst = [float(e) for e in s.split()]          # Now lst is a list of floats.
    output = [e for e in lst if 0 < e < 100]
    

    假设您正在使用Python3(bec)