: Hey!! I need to write a program that gives lettergrades to data from a list. I have written this but when i import it, i have trouble. It says:
: Traceback (most recent call last):
: File "<stdin>", line 1, in ?
: File "grades.py", line 5
: Print "A"
:
: Grades.py is:
: def Grade(L):
: G=L[:]
: for i in L:
: if i >= 90 and i <= 100:
: Print "A"
: elif i>= 80 and i < 90:
: Print "B"
: elif i >= 70 and i < 80:
: Print "C"
: elif i >= 60 and i< 70:
: Print "D"
: elif i < 60:
: Print "F"
:
: Thank you,Please Help!!!
Here is my version of your code:
def Grade(L):
for i in L:
if i >= 90:
print "A"
elif i >= 80:
print "B"
elif i >= 70:
print "C"
elif i >= 60:
print "D"
else:
print "F"
if __name__ == '__main__':
Grade([99,88,77,66,55])
Notice that "print" (lowercase p) is different than "Print" (uppercase P). Also notice that there's no reason to make a copy of your list. Also notice that you can really simplify your conditional expressions. There's no reason to check that i < 90 since that line won't execute unless it fails the first test. Also note that the "if __name__" test at the bottom of a script will execute if you are running your script by itself, but not if you import it into another script. It's a handy way of adding "self-test" code to your modules.