Python _ arithmetic functions

Source: Internet
Author: User

Take the grades list as an example to define the output, sum, average, variance, and standard deviation functions, and output the corresponding values.

Grades = [100,100, 90, 40, 80,100, 85, 70, 90, 65, 90, 85, 50.5] # define the output function def print_grades (grades): for grade in grades: print grade # define the sum function def grades_sum (grades): total = 0 for grade in grades: total + = grade return total # define the average function def grades_average (grades ): sum_of_grades = grades_sum (grades) average = sum_of_grades/float (len (grades) return average # define the variance function def grades_variance (scores): average = grades_average (scores) variance = 0 for score in scores: variance + = (average-score) ** 2 return variance/len (scores) # defines the Standard Deviation Function def grades_std_deviation (variance ): return variance ** 0.5 variance = grades_variance (grades) # Call the function to output the corresponding print print_grades (grades) print grades_sum (grades) print grades_average (grades) print grades_variance (grades) print grades_std_deviation (variance)

 

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.