How to average and sort integers in the list in python

Source: Internet
Author: User
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 I

The 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!

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.