Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在python中从小到大打印数字?_Python 3.x_Numbers - Fatal编程技术网

Python 3.x 如何在python中从小到大打印数字?

Python 3.x 如何在python中从小到大打印数字?,python-3.x,numbers,Python 3.x,Numbers,我有一个关于输入一些数字并从小到大排列的家庭作业 这里的代码显示了错误,我不确定这意味着什么以及如何修复它 # -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ list1 = [] def disp_data(): for items in datas: print(items,end=" ") print() while True: h=inpu

我有一个关于输入一些数字并从小到大排列的家庭作业

这里的代码显示了错误,我不确定这意味着什么以及如何修复它

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

list1 = []
def disp_data():
    for items in datas:
        print(items,end=" ")
    print()
while True:
    h=input("input a number(press enter to exit):")
    if h == "":
        break
    else:
        datas = list1.append(h)
print('before:',end =" ")
disp_data()
n = len(datas)-1

for i in range(0,n):
    for j in range(0,n-i):
        if (datas[j]>datas[j+1]) :
            datas[j],datas[j+1]=datas[j+1],datas[j]

print("after:",end=" ")
disp_data()


TypeError: 'NoneType' object is not iterable
我已经写了一篇:

def disp_data():
    for items in datas:
        print(items,end=" ")
    print()

datas = [3,5,2,1]
print('before',end =" ")
disp_data()
n = len(datas)-1

for i in range(0,n):
    for j in range(0,n-i):
        if (datas[j]>datas[j+1]) :
            datas[j],datas[j+1]=datas[j+1],datas[j]

print("after",end=" ")
disp_data()
任何想法或错误语法,请编辑或回答。谢谢,列表方法E append不会返回None,因此datas=list1.append使数据为None。一个简单的修复方法是重命名list1数据:

[……]

datas = []
while True:
    h = input("input a number(press enter to exit):")
    if h == "":
        break
    else:
        datas.append(h)