当前位置:网站首页>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]
边栏推荐
- Design a clock frequency division circuit that can be switched arbitrarily
- Keil use details -- magic wand
- Imx6ull bare metal development learning 1-assembly lit LED
- Detailed summary of FIO test hard disk performance parameters and examples (with source code)
- Sizeof (function name) =?
- [three tier architecture]
- Talk about the function of magnetic beads in circuits
- STM32 --- configuration of external interrupt
- C WinForm [get file path -- traverse folder pictures] - practical exercise 6
- Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
猜你喜欢
![[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code](/img/58/576b6b77509ed7a9bef138f3899e37.jpg)
[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code

Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic
![[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication](/img/08/7f28008a4aa999650998ba8dee5d8e.jpg)
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication

MHA High available Cluster for MySQL
![[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement](/img/54/78e4e10724b2762274b06debb10877.jpg)
[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement

Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!

【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
![[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture](/img/c5/22c6148873508b9205972e1ad970a3.jpg)
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture

Talk about the function of magnetic beads in circuits

Briefly talk about the identification protocol of mobile port -bc1.2
随机推荐
Explain task scheduling based on Cortex-M3 in detail (Part 1)
Management and use of DokuWiki
亿学学堂给的证券账户安不安全?哪里可以开户
Hardware 3 -- function of voltage follower
[trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
Vofa+ software usage record
实例006:斐波那契数列
MHA High available Cluster for MySQL
Use indent to format code
Stablq of linked list
2020-05-21
Shape template matching based on Halcon learning [9] PM_ multiple_ dxf_ models. Hdev routine -- [read and write XLD from DXF file]
STM32---IIC
STM32---ADC
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
Working principle and type selection of common mode inductor
Stm32--- systick timer
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
Take you to understand the working principle of lithium battery protection board