7. Sending a letter


#1



7. Sending a letter


Hey everyone,
I just want to ask a question, There is one thing I don't get. I am a complete beginner so I am not really familiar with programming, thus this may sound stupid, anyway: how is it possible, that '(score)' is somehow linked with the function above (computing average)....aren't they linked? Then how does the computer know, that '(score)' is a number for. ex., how come it is not necessary to define it? I guess I didn't get the concept of arguments in general.

Thanks anyone!


Replace this line with your code. 

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"
    
    return get_average(lloyd)
    return get_letter_grade(student)


#2

score is the function parameter, its serves as placeholder until you pass an argument (a number in this case) when calling the function


#3

As of defining the function, the program does not know whether score is a number, a string, a list, a dictionary, etc. As far as the program is concerned score could be anything. And the the program could care less. It's just a placeholder for the whatever you pass into the function when you actually call it. In other words think of parameters like variables, whenever you call a function, the argument you pass into it becomes the value for score. For instance when you called:

return get_average(lloyd)

You were essentially telling the program to run get_average(score) except now, score = lloyd. Until a function is actually called, the parameters you have set are valueless placeholders. Once you call the function and pass in arguments for those parameters, they take on value and purpose.


#4

Thank you guys! It makes sense now:)


#5

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