Python Example 1 (basic knowledge consolidation) and python example knowledge Consolidation

Source: Internet
Author: User

Python Example 1 (basic knowledge consolidation) and python example knowledge Consolidation

Exercise 1: create a program that prompts you to enter a value in the while loop, and enter a value more to build a list. When the user ends the input (Press Enter), the input value itself, the number of input values, the input value and, the input minimum and maximum values, and the average value are printed.

Sample Code:

Note: This program uses the int () type conversion method and the minimum value and maximum value acquisition method list. index (min (list) and list. index (max (list), which retrieves the index value and the corresponding value based on the index value.

Exercise 2: create some vocabulary, such as the title ('the ', 'A'), topic ('cat', 'dog', 'Man ', and 'Woman '), verbs ('shanghai', 'ran ', 'jumped'), and adverbial ('loudly', 'quietly ', 'Well', 'badly'), etc, after that, it loops 5 times. In each iteration, random is used. the choice () function selects the title, subject, verb, and adverbial. It selects the title, subject, verb, and adverbial, and then prints the statement.

Sample Code:

Modify the program: modify the code, so that you can enter a number in the command line, the program will enter the number of lines represented by this number. If no command line parameter is specified, five lines are printed as before by default.

Code after modification:

Execution result:

 

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.