Acceptable code seemed sloppy


#1



https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/2?curriculum_id=4f89dab3d788890003000096

It works, I made the weighted_average variable and did the math that way for a more legible code but feel like maybe it could be better in some way. It just seems unnecessarily lengthy.


#lengthy weird code
def get_average(student):
    homework = average(student['homework'])
    quizzes = average(student['quizzes'])
    tests = average(student['tests'])
    homework = homework * .1
    quizzes = quizzes * .3
    tests = tests * .6
    weighted_average = homework + quizzes + tests
    return weighted_average

#maybe this is better?

def get_average(student):
    homework = average(student['homework']) * 1
    quizzes = average(student['quizzes']) * .3
    tests = average(student['tests']) * .6
    weighted_average = homework + quizzes + tests
    return weighted_average


#2

To help prevent errors, and to make floats more readable best practice is to always preface with a leading zero before the decimal point.

0.1, 0.3, 0.6

We can get the line count down by returning the expression directly.

    return homework + quizzes + tests

#3

Thanks, that makes sense