当前位置:网站首页>Example 005: three numbers sorting input three integers x, y, Z, please output these three numbers from small to large.
Example 005: three numbers sorting input three integers x, y, Z, please output these three numbers from small to large.
2022-07-05 08:22:00 【Lazy smile】
example 005: Three number order
subject : Enter three integers x,y,z, Please output these three numbers from small to large .
Method 1 :
# Loop through each number , Compare two numbers , If the former number is greater than the latter number, the two numbers will exchange positions
# Enter three numbers and save to raw in
raw = []
for i in range(3):
x = int(input('int%d: ' % (i + 1)))
raw.append(x)
# Loop through each number , Compare two numbers , If the former number is greater than the latter number, the two numbers will exchange positions
for i in range(len(raw)):
for j in range(i, len(raw)):
if raw[i] > raw[j]:
raw[i], raw[j] = raw[j], raw[i]
print(raw)
int1: 3
int2: 2
int3: 6
[2, 3, 6]
Method 2 :
Call the sort function directly sorted()
# Enter three numbers and save to raw2 in
raw2 = []
for i in range(3):
x = int(input('int%d: ' % (i + 1)))
raw2.append(x)
# Direct call function sorting
print(sorted(raw2))
int1: 5
int2: 7
int3: 3
[3, 5, 7]
边栏推荐
- Shape template matching based on Halcon learning [vi] find_ mirror_ dies. Hdev routine
- Slist of linked list
- WiFi wpa_ Detailed description of supplicant hostpad interface
- [trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
- What are the test items of power battery ul2580
- Live555 push RTSP audio and video stream summary (I) cross compilation
- Sql Server的存储过程详解
- Verilog -- state machine coding method
- Compilation warning solution sorting in Quartus II
- Adaptive filter
猜你喜欢
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
剑指 Offer 05. 替换空格
实例006:斐波那契数列
[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)
Hardware 3 -- function of voltage follower
[three tier architecture]
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
Semiconductor devices (I) PN junction
Some thoughts on extracting perspectives from ealfa and Ebeta
【三层架构】
随机推荐
MySQL MHA high availability cluster
Buildroot system for making raspberry pie cm3
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine
C language # and #
Synchronization of QT multithreading
STM32 single chip microcomputer - external interrupt
Various types of questions judged by prime numbers within 100 (C language)
Live555 push RTSP audio and video stream summary (III) flower screen problem caused by pushing H264 real-time stream
STM32---ADC
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
Soem EtherCAT source code analysis II (list of known configuration information)
Hardware 3 -- function of voltage follower
Management and use of DokuWiki (supplementary)
Wifi-802.11 negotiation rate table
如何写Cover Letter?
STM32 --- configuration of external interrupt
Brief discussion on Buck buck circuit
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
Tailq of linked list