This article describes how to sort the list key integers by using Python, and share the code with you ~~~ This article describes how to sort the list key integers by using Python, and share the code with you ~~~
Problem
Defines an int-type one-dimensional array, containing 40 elements, used to store the scores of each student, generate 40 0 ~ A random integer between 100,
(1) store them in a one-dimensional array, calculate the number of students whose scores are lower than the average score, and output them.
(2) output the 40 scores in the order from high to low.
Solution (python)
#! /Usr/bin python # coding: utf-8from _ Ure _ import pision # implement precise division, for example, 4/3 = 1.333333 import randomdef make_score (num): score = [random. randint (0,100) for I in range (num)] return scoredef less_average (score): num = len (score) sum_score = sum (score) ave_num = sum_score/num less_ave = [I for I in score if IThe preceding section describes how to average and sort integers in the list in python. For more information, see other related articles in the first PHP community!