[Tutor] REport Card Question

Wayne Werner waynejwerner at gmail.com
Mon Nov 29 02:11:02 CET 2010


On Sun, Nov 28, 2010 at 6:50 PM, Andre Jeyarajan
<andrejeyarajan at rogers.com>wrote:

>  Write a code that will take an input from a user (numerical grade) and
> convert their numerical grade into a letter grade that is accompanied by a
> “smart” statement.
>
>  def grade_score(grade):
>
>     if grade >=95 and grade <= 100:
>
>         print 'A+, Excellent'
>
>     elif grade >=85 and grade < 95:
>
>         print 'A, Good Work'
>
>     elif grade >=80 and grade < 85:
>
>         print 'A-, Good Work, but you could do better'
>
>     elif grade >=75 and grade < 80:
>
>         print 'B, Try Harder'
>
>     elif grade >=70 and grade < 75:
>
>         print 'B-, Try Harder'
>
>     elif grade >=65 and grade < 70:
>
>         print 'C, Work Harder'
>
>     elif grade >=60 and grade < 65:
>
>         print 'C-, Work Harder'
>
>     elif grade >=55 and grade < 60:
>
>         print 'D, Study Harder'
>
>     elif grade >=50 and grade < 55:
>
>         print 'D-, Study Harder'
>
>     elif grade >=0 and grade < 50:
>
>         print 'F, You Failed'
>
>     else:
>
>         print "You did not enter an appropriate value, please run the
> program again!"
>
>
> grade = raw_input('Put your grade here:’)
>
>
> grade_score()
>
>
> Put your grade here:77
>
> Traceback (most recent call last):
>
>   File "/Users/andre.jeyarajan/Documents/workspace/Chapter 5
> Problems/src/ReportCardQuestion.py", line 28, in <module>
>
>     grade_score()
>
>
This line tells you why it doesn't work:


> TypeError: grade_score() takes exactly 1 argument (0 given)
>

Are you familiar with functions? When you define the function you define it
as taking one parameter:

def grade_score(grade):
    # Code here

but then when you call it:

grade_score()

you don't give it any parameters (or arguments). The traceback tells you
that you need to provide it 1 argument and that you gave it 0 instead.

If you called

grade_score(3, 150)

you would get a similar error, only it would say (2 given) instead.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101128/a1d285de/attachment.html>


More information about the Tutor mailing list