Home >Backend Development >Python Tutorial >python sort three numbers from small to large

python sort three numbers from small to large

angryTom
angryTomOriginal
2020-02-29 13:35:0526395browse

python sort three numbers from small to large

Python three numbers are sorted from small to large

1. First define a function paiLie(); then within the paiLie function Use a for loop and input to get three numbers and store them in the list; finally call the sort() method of the list to sort.

def paiLie():
    result = []
    for i in range(3):
        x = input("请输入数字:")
        result.append(x)
    result.sort()
    print result

2, Calling

paiLie()
请输入数字:56
请输入数字:5
请输入数字:89

Running result:

[5, 56, 89]

numerouspython Video tutorial , all on the PHP Chinese website, welcome to learn online!

The above is the detailed content of python sort three numbers from small to large. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn