Python entry tool-codecademy-share a simple exercise

Source: Internet
Author: User

For the data analysis of the students, to do in-depth, R and Python will be one, the 0 basis how to learn it? https://www.codecademy.com/is a good choice to practice by introducing, letting you practice, practicing by going to the next step (or choosing a chapter of your own), not giving you an answer, passing it right, or putting it there until you will, You can clearly see which part of yourself has been completed, overall progress, etc. Math majors have no reason to be afraid of programming students can learn r, you see the R code as if you see the mathematical formula you learned, it will be easier to accept and understand. The Python language is a bit more restrictive.

The free version of the Python Basics is enough, to finish this course, basically will have a basic understanding of Python, followed by the study of various data analysis commonly used modules (NumPy, pandas, Matplolib) will be relatively easy. For example, the following example is actually a large section of the 10 small steps to complete, each step through will go to the next step, gradually, from simple into the complex, very good understanding. Codecademy the exercises above are not according to the project, a bit like a module, but our goal is to use Python to support data analysis work, not as a Python programmer.

The basic step must be the code, one step at a pace, or a indentation will be able to dry people down.

Objective to find the average grade of a class and the corresponding result type.

#字典的定义方式
Lloyd = { "name":"Lloyd", "Homework": [90.0,97.0,75.0,92.0], "Quizzes": [88.0,40.0,94.0], "tests": [75.0,90.0]}alice= { "name":"Alice", "Homework": [100.0,92.0,98.0,100.0], "Quizzes": [82.0,83.0,91.0], "tests": [89.0,97.0]}tyler= { "name":"Tyler", "Homework": [0.0,87.0,75.0,22.0], "Quizzes": [0.0,75.0,78.0], "tests": [100.0,100.0]}
To print the student's name and its score: students=[Lloyd,alice,tyler] foreachinchStudents:print each["name"] Print each["Homework"] Print each["Quizzes"] Print each["tests"]lloyd[90.0,97.0,75.0,92.0][88.0,40.0,94.0][75.0,90.0]alice[100.0,92.0,98.0,100.0][82.0,83.0,91.0][89.0,97.0]tyler[0.0,87.0,75.0,22.0][0.0,75.0,78.0][100.0,100.0]
# Customize a function to find the average of a listdef average (numbers): Total=sum (numbers) total=float(total)returntotal/Len (Numbers)

#自定义一个函数, for a student's comprehensive results, first find the average score of each category, and then multiply the weights of each class, and get his comprehensive results def get_average (student): Homework=average (student["Homework"]) Quizzes=average (student["Quizzes"]) tests=average (student["tests"]) return 0.1*homework+0.3*quizzes+0.6*Tests
#自定义一个函数, divide grades into different levels of Def Get_letter_grade (score):ifscore>= -: return "A"Elif Score>= theand score< -: return "B"Elif Score>= -and score< the: return "C"Elif Score>= -and score< -: return "D" Else: return "F"

#测试一下, Lloyd's comprehensive score Get_letter_grade (Get_average (Lloyd))

#定义一个函数, ask for a class of comprehensive results def get_class_average (students): Results=[]; forStudentinchStudents:results.append (Get_average (student))returnaverage (results)
#假设这个班有三个人
Print Get_class_average ([Lloyd,alice,tyler]) Print Get_letter_grade (Get_class_average ([Lloyd,alice,tyler]))

Python entry tool-codecademy-share a simple exercise

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.