当前位置:网站首页>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]
边栏推荐
- STM32 --- GPIO configuration & GPIO related library functions
- Introduction of air gap, etc
- [trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
- Detailed summary of FIO test hard disk performance parameters and examples (with source code)
- Volatile of C language
- STM32 single chip microcomputer -- debug in keil5 cannot enter the main function
- OLED 0.96 inch test
- 如何写Cover Letter?
- How to copy formatted notepad++ text?
- VESC Benjamin test motor parameters
猜你喜欢

How to write cover letter?

My-basic application 2: my-basic installation and operation

Solutions to compilation warnings in Quartus II

Working principle and type selection of common mode inductor
![[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc](/img/9e/2524cbb9b90135c54669ba8d5338b7.jpg)
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc

Summary -st2.0 Hall angle estimation

Hardware and software solution of FPGA key chattering elimination

Hardware 1 -- relationship between gain and magnification

STM32 single chip microcomputer -- volatile keyword

Compilation warning solution sorting in Quartus II
随机推荐
Compilation warning solution sorting in Quartus II
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
Talk about the function of magnetic beads in circuits
Anonymous structure in C language
STM32---IIC
Naming rules for FreeRTOS
【三层架构】
On boost circuit
Briefly talk about the identification protocol of mobile port -bc1.2
Why is 1900 not a leap year
[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
STM32 --- GPIO configuration & GPIO related library functions
实例009:暂停一秒输出
Sword finger offer 09 Implementing queues with two stacks
剑指 Offer 09. 用两个栈实现队列
STM32 --- configuration of external interrupt
The firmware of the connected j-link does not support the following memory access
matlab timeserise
Semiconductor devices (III) FET