How is Everybody Doing?


#1

Once again I'm in the dark. code looks right but error message says:
Oops, try again.
Did you remember to print the average of the class? It looks like "83.8666666667" wasn't printed.

and I have a print statement but it won't print out.

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]
}
# Add your function below!
def average(numbers): #this function gets averages 
    total = sum(numbers)
    float(total)
    average = total / float(len(numbers))
    return average
    
def get_average(student): #this function gets average for h,q,t
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return homework * 0.1 + quizzes * 0.3 + tests * 0.6    
    
def get_letter_grade(score): # this function gets total average
    if score >89:
        return "A"
    elif score >79:
        return "B"
    elif score >69:
        return "C"
    elif score >59:
        return "D"
    else:
        return "F"        
def get_class_average(students):
    students=[lloyd, alice, tyler]
    results = []
    for student in students:
        results.append(get_average(student))
    return average(results)
    print get_class_average(students)
    print get_letter_grade(get_class_average(students))
    print results

What's wrong?


#2

Here is link

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


#3

on these lines

def get_class_average(students):
    students=[lloyd, alice, tyler]
    results = []
    for student in students:
        results.append(get_average(student))
    return average(results)
    print get_class_average(students)
    print get_letter_grade(get_class_average(students))
    print results

your print statements are being called inside that function it has to be

def get_class_average(students):
    students=[lloyd, alice, tyler]
    results = []
    for student in students:
        results.append(get_average(student))
    return average(results)
print get_class_average(students)
print get_letter_grade(get_class_average(students))
#print results #this will give an error because result
              #results is not defined

#4

I though that the average of the students was being stored in the variable results and that by printing results it would have printed the stored value. and i thought that was one of the requirements of the exercise.


#5

The whole fix code and then having to refresh the exercise to have the code run right is most annoying. But your fix worked thank you.


#6

The average of each student was being stored in result as a computation in the function get_class_average(students): which means that results variable only exists inside that function.
outside the function you will have to create it to use it


#7

So it is a local vs Global variable issue where I was trying to call a local variable outside a function. Had it been Global it would have worked?


#8

Yes if results was a global variable it would have worked


#9

here is a small example to demonstrate

result = 5

def add(n):
    #adds a number to  a global variable
    global result
    result+=n
    
add(5)
print result #10

without calling the global key word before result will yield an error


#10

can creating the variable globally at the beginning of the program say at the very top also work?


#11

Also I have programed in BASIC so I have some idea but that was 25 years ago. Some interpreters have colored lines that help with indentation. Is there one for Python?


#12

yes defining it globally at the beginning will also work like

global result

def set(n):
    #assigns a number to  a global variable
    result = 5
    
set(5)
print result #5

#13

what text editor do you use for python locally on your pc


#14

Im just using the in browser on the website I think otherwise I am using windows 10 and firefix browser. If that is the answer you are looking for. Im not sure.


#15

You can also test python code in your own computer(offline)

To get the interpreter locally i suggest you download python 3.5 here (make sure to install it as admin and make sure to select the option of adding it to your system path (if using windows))
After installing python 3.5 now go on an download sublime text3 here

All you have to do now create a new python project, save it and hit ctrl+b to run it and a console window will pop up from below showing the result.
NB: (Unlike previous version sublime text 3 does not require any build configurations to run python code)

NB: Note sublime text does not support user inputs using raw_input() or input()

You can also look into getting Jetbrain's PyCharm


This is how it looks like when you write code in it

But then if you want to stick to using online editors you have some options too
like
repl.it
codeacademy labs


#16

Great Thank you I will check them out as I intend to learn several languages, Python, javascript, c++, and already have some knowledge of HTML, BASIC and was starting to learn FORTRAN and COBAL> Back in the day.


#17

RUBY looks like a great language might try learning that one too


#18

Ruby seems a lot easier for building web applications(Ruby on Rails)


#19

What would you suggest for building a math statistic program something that uses multiple data bases and has to crunch lots of numbers?


#20

if you are looking to write scripts that will model and analyze statical data then you can definitely use python(with help of libraries) but then software like
IBM's SPSS Statistics and Matlab(Statistics Toolbox) also make it you do advanced analysis.

But if you are look to build a customized statistics application you can still use python ad a little bit of c