先把最小的数放在x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,再用x与z进行比较,如果x>z则将x与z的值进行交换,这样能使x最小
# -*- coding utf-8 -*-
l = []
for i in range(3):
x = int(input("integer:\n"))
l.append(x)
l.sort()
print(l)
integer:
123
integer:
456
integer:
22
[22, 123, 456]
ll = []
ll_len = int(input("number:\n"))
for i in range(ll_len):
x = int(input("integer:\n"))
ll.append(x)
for i in range(ll_len):
for j in range(ll_len -1):
if ll[i] < ll[j]:
ll[i],ll[j] = ll[j],ll[i]
print(ll)
print(ll)
number:
5
integer:
22
integer:
55
integer:
99
integer:
1
integer:
5
[1, 5, 22, 55, 99]