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: