当前位置:网站首页>Topic 66: input array, exchange the largest element with the first element, exchange the smallest element with the last element, and output array.
Topic 66: input array, exchange the largest element with the first element, exchange the smallest element with the last element, and output array.
2022-06-12 18:16:00 【A little vegetable loving girl】
Code :
# Convert the input array to list, And every element is int Type data
array_input = input(' Please enter an array , Separated by commas :')
array_str_list = array_input.split(',')
array = [int(array_str_list[i]) for i in range(len(array_str_list))]
# The largest element is exchanged with the first element
max_element = max(array)
max_element_index = array.index(max_element)
array[max_element_index] = array[0]
array[0] = max_element
# The smallest element exchanges with the last element
min_element = min(array)
min_element_index = array.index(min_element)
array[min_element_index] = array[-1]
array[-1] = min_element
print(array)Running results :

边栏推荐
- GD32F4xx控制DGUS触控按键
- 干货 | 一文搞定 pytest 自动化测试框架(二)
- C#简单介绍
- Resttemplateconfig configuration print request response log under soringboot
- js判断回文数
- JS sum of two numbers
- Installation and configuration of window version pytorch entry depth learning environment
- Comparison of disk mapping tools for network disk and object cloud storage management
- 有源差分晶振原理圖以及LV-PECL、LVDS、HCSL區別
- Stream flow precautions
猜你喜欢

Vant3+ts dropdownmenu drop-down menu, multi data can be scrolled

A method of quickly reusing wechat login authorization in app

小程序和App同时拥有?两者兼得的一种技术方案

General differences between SQL server versions released by Microsoft in different periods so far, for reference

Installation and configuration of window version pytorch entry depth learning environment

企业架构的第一性原理

用好IDE,研发效能提速100%

Variable of C #

General differences between SQL server versions released by Microsoft in different periods so far, for reference

HTTP cache < strong cache and negotiation cache >
随机推荐
Stream flow precautions
C language practice (4) -- multiplication and division of large numbers
js将数组中的0移动到末尾
在同花顺开户证券安全吗
JS中的字符串(含leetcode例题)<持续更新~>
js判断回文数
Vant3 +ts packaged simple step advancer component
Leetcode 674 longest incrementing substring
VirtualLab basic experiment tutorial -5 Poisson bright spot
有源差分晶振原理图以及LV-PECL、LVDS、HCSL区别
Write a select based concurrent server
USB to serial port - serial port driver type
小程序和App同时拥有?两者兼得的一种技术方案
High-Speed Layout Guidelines 未完...
The server time zone value ‘�й���ʱ��‘ is unrecognized or represents more than one time zone. ......
轻量、便捷的小程序转App技术方案,实现与微信/流量App互联互通
"Big fat • small lesson" - talk about big file segmentation and breakpoint sequel
Typescript common types (I)
Office application cannot start normally 0xc0000142
Esp-idf adds its own components