Problems with my first python script
<p>I am trying to write a simple grading script based off an existing script that i found in a tutorial online. The goal is to ask the user their score and give the corresponding grade.</p>

<p>Here is the original code:</p>

<pre><code>def letterGrade(score):
    if score &gt;= 90:
        letter = 'A'
    else:   # grade must be B, C, D or F
        if score &gt;= 80:
            letter = 'B'
        else:  # grade must be C, D or F
            if score &gt;= 70:
                letter = 'C'
            else:    # grade must D or F
                if score &gt;= 60:
                    letter = 'D'
                else:
                    letter = 'F'
    return letter
</code></pre>

<p><strong><em>this btw didnt work at all and i really dont get the "def" command since its not mentioned again? No errors</em></strong></p>

<p>Anyway, here is my new modified code from what i have been learning from books and online...</p>

<pre><code>score = float(input("What is your score"))
if score &gt;= 90:
    letter = 'A'
else:   # grade must be B, C, D or F
    if score &gt;= 80:
        letter = 'B'
    else:  # grade must be C, D or F
        if score &gt;= 70:
            letter = 'C'
        else:    # grade must D or F
            if score &gt;= 60:
                letter = 'D'
            else:
                letter = 'F'
print (letter)
input ("Press Enter to Exit")
</code></pre>

<p><strong><em>This code doesnt work either, but at least it is asking for user input now.  No errors</em></strong></p>

<p>What am i missing here?</p>

<p>Ok let's first start with some pseudo code, I always try to pseudo code my problems and draw them out as much as possible, it helps me and it might help you. So the grading scale you seem to have implemented is something like this. If you have a grade lower than 100 but greater than or equal to 90 it is an A, lower than 90 but greater than or equal to an 80 it is a b, so on and so on. Let's use conditional statements for this. You can nest it like you had, but setting up the order of conditions may be what you need. So if the grade is not greater than or equal to 90, then the grade can only be lower than 90, thus a B, C, D or F.</p>

<pre><code>if (grade &gt;= 90):
    letter = 'A'
elif (grade &gt;= 80):
    letter = 'B'
elif (grade &gt;= 70)
    letter = 'C'
elif (grade &gt;= 60)
    letter = 'D'
else:
    letter = 'F'
</code></pre>

<p>So with these conditional statements we go through the process of finding the grade, as explained a bit above the code, if the user does  not have a grade greater than 90, it hops to the next elif which checks if it is greater than or equal to 80, so on and so on, if grade at one point not greater than or equal to 60, then all other values lower than 60 will be an F.</p>

<p>Now to cover 'def'. You use def to define a function. Here is a generic layout:</p>

<pre><code>def functioname(parameters, parameters):
    stuffgoeshere
</code></pre>

<p>Now, the parameters are optional, it all depends if you need to pass any data to the function, in your case, you are passing the grade of the user:</p>

<pre><code>def gradeLetter(grade):
    if (grade &gt;= 90):
        return 'A'
    elif (grade &gt;= 80):
        return 'B'
    elif (grade &gt;= 70)
        return 'C'
    elif (grade &gt;= 60)
        return 'D'
    else:
       return 'F'
</code></pre>

<p>At this point you can call the function, passing in the value the user typed in. We return the character in the function, so that you can assign it to a variable to print it, or you can just print it within the function, whichever is your preference.</p>

<pre><code>g = input("Please enter your grade: ")
l = gradeLetter(g)
print("Your letter grade is " + l)
</code></pre>

<p>Hope this helps you out. If you have any questions feel free to comment below. </p>

python