我只写一个函数:
>>> def littleFunc():
data =[] #初始化列表
for i in range(9):#一个
for循环 num = int(raw_input("input a number please: "))#控制输入转为int
data.append(num)#放入列表
data.sort()#排序
print data#输出
python的程序
扩展名是.py
程序执行结果:
>>> littleFunc()
input a number please: 1
input a number please: 3
input a number please: 5
input a number please: 7
input a number please: 8
input a number please: 4
input a number please: 9
input a number please: 6
input a number please: 2
[1, 2, 3, 4, 5, 6, 7, 8, 9]