用python写一个小程序,让用户输入任意9个数字,然后输出排序后的结果。
展开全部
我只写一个函数:
>>> 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]
>>> 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]
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询