Python exercise question 005: three numbers are output in ascending order and python005

Source: Internet
Author: User

Python exercise question 005: three numbers are output in ascending order and python005

[Python exercise question 005]Input three integers x, y, and z. Please output these three numbers from small to large.

-----------------------------------------------------------------------

It should be easier to think about this question: it is nothing more than getting three numbers first, and then compare the size, output in order. However, you may encounter a problem during code writing: you may need to specify multiple delimiters (English commas, Chinese commas, and spaces) for inputting unspecified delimiters during input, but str. split () only accepts one separator.

After searching the Internet, we found that we could use regular expressions to solve this problem, so we had the import re line. The Code is as follows:

Import rex, y, z = re. split (', |, |', input ('enter three numbers, separated by commas or spaces:') x, y, z = int (x ), int (y), int (z) maxNo = max (x, y, z) minNo = min (x, y, z) print (maxNo, x + y + z-maxNo-minNo, minNo)

I have long known that regular expressions are very powerful, but it is too difficult to touch them ...... You must study this part in the future!

 

++

Source: getting started with programming languages: 100 typical examples [Python]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.