On Sat, Oct 4, 2008 at 12:11, David <[EMAIL PROTECTED]> wrote:
> I am quite happy with my code, but there is a bug: if the score is 100, then
> the program calculates 100/10 = 10. However, the tuple runs to 9, leaving me
> with an error message: IndexError: tuple index out of range
>
> I can't figure out how to solve that problem...
> I also suspect that my code clearly exposes me as a beginner :-) What would
> be the pythonic way of solving that exercise?
>
> # exam score to grade conversion
> # Zelle, ch. 4, exercise 7
> x = ("F", "F", "F", "F", "F", "E", "D", "C", "B", "A")
> score = raw_input("What's your exam score (0-100)? ")
> grade = x[int(score)/10]
> print "Your grade is:", gradePython starts counting from zero so to access the first item in x it would be x[0]. When you do x[10] you actually are requestting the 11th value in x instead of the 10th and this does not exist. You should be able to fix this yourself now. Greets Sander _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
