How did this pass?


#1



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


So my code passed the exercise without printing anything. When I try my code in PyCharm it gives me an invalid syntax error on the last line of code. What gives? I'm really trying to wrap my head around this assuming I did something wrong. Or is it just the game making a mistake?


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):
    total = (float(sum(numbers)))/len(numbers)
    return total
    
def get_average(student):
    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):
    if score >= 90:
        return "A"
    elif score >= 80:
        return "B"
    elif score >= 70:
        return "C"
    elif score >= 60:
        return "D"
    else:
        return "F"
        
    print get_letter_grade(get_average(lloyd))


#2

Move your print statement back 2 spaces and you will see a letter grade! :smiley: Sorry I am at lost for words for why it passed but I will look into it for ya if you want more info.


#3

I tried that and still get the same invalid syntax error.


#4

Ok well I have never used PyCharm but more than likely they are on Python 3. Codecademy is on Python 2 until they update it hopefully later on this summer! So there might be some error that doesn't exist in Python 2 that does exist in Python 3 because things have changed in how stuff is structured etc.


#5

Yeah, that makes complete sense. I didn't realize Codeacadamy wasn't on Python 3. Is it still worth going through the whole course here then?


#6

oh yeah. I mean its not like Python 2 is completely obsolete lol You will still learn a lot of Python's basic and advanced functions and such. Now, I haven't looked to in depth with the differences between Python 2 and Python 3 but I am sure a quick google search can bring something up for that.... And if I had to guess there will be some big differences but the core language should be the same.

Results from Quick Google Search: http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html

https://wiki.python.org/moin/Python2orPython3

https://www.fullstackpython.com/python-2-or-3.html

These at a quick glance seemed like reasonable resources but take them with a grain of salt as always. I will try and find something more official. Here is the official Python website: https://www.python.org/ and apparently the link from that website for this type of question is the wiki python link above so that should be solid then I would assume if they are using it.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.