马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 不二如是 于 2022-8-29 17:49 编辑
一星答案:
def arrOrder(the_list):
num = max(the_list)-min(the_list)
dic = {}
for i in range(1,len(the_list)+1):
dic[i] = the_list[i-1]
new_list = []
for a in dic:
if dic[a] == min(the_list):
dic[a] += num
elif dic[a] == max(the_list):
dic[a] -= num
new_list.append(dic[a])
print(new_list)
if __name__ == '__main__':
the_list = [3,4,2,1,6,10,7,8]
arrOrder(the_list)#[3, 4, 2, 10, 6, 1, 7, 8]
二星答案:
import random
counts = 100
while counts:
temp = [random.randint(1, 100) for i in range(10)]
total = sum(temp)
print(temp)
temp[temp.index(max(temp))], temp[0] = temp[0], temp[temp.index(max(temp))]
temp[temp.index(min(temp))], temp[-1] = temp[-1], temp[temp.index(min(temp))]
print(temp)
if total != sum(temp):
print('There is something wrong!')
break
counts -= 1
三星答案:
基础语法:
算法讲解:
|