pythonExample100/JCP037.py

30 lines
713 B
Python
Raw Permalink Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

'''
【程序37】
题目对10个数进行排序
1.程序分析可以利用选择法即从后9个比较过程中选择一个最小的与第一个元素交换
      下次类推即用第二个元素与后8个进行比较并进行交换。       
2.程序源代码:
'''
if __name__ == "__main__":
N = 10
# input data
print 'please input ten num:\n'
l = []
for i in range(N):
l.append(int(raw_input('input a number:\n')))
print
for i in range(N):
print l[i]
print
# sort ten num
for i in range(N - 1):
min = i
for j in range(i + 1,N):
if l[min] > l[j]:min = j
l[i],l[min] = l[min],l[i]
print 'after sorted'
for i in range(N):
print l[i]