- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex67.py
More file actions
Latest commit
26 lines (25 loc) · 610 Bytes
/
Copy pathex67.py
File metadata and controls
26 lines (25 loc) · 610 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'''
输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
'''
l= []
whileTrue:
n=input("输入一个数字:(按空格键结束)")
ifn==" ":
break
l.append(int(n))
j=0
# 找到最大元素的位置
foriinrange(1, len(l)):
ifl[i] >l[j]:
j=i
i+=1
max_index=j
# 找到最小元素的位置
foriinrange(len(l)):
ifl[i] <l[j]:
j=i
i+=1
min_index=j
l[0], l[max_index] =l[max_index], l[0]
l[-1], l[min_index] =l[min_index], l[-1]
print(l)