On Mon, Sep 19, 2016 at 11:01:30PM +0000, Gampper, Terry wrote:
> I started my journey with Python last week and find it to be an
> easy-to-learn language. I am currently teaching introduction to
> computer programming. One of the assignments we are working on
> involves an instructor giving a series of 5 tests, and the lowest
> score is dropped, then calculating the percent. Here is my attempt at
Thank you for showing your code!
Do I understand that you are the *teacher* in this course, rather than a
student? We try not to do student's work for them, although we may
sometimes guide them towards the right direction. But if you are the
teacher, then of course we're happy to help.
> name = input("Enter Student's Name: " )
> tscore1 = input ("Enter test score 1: ")
> tscore2 = input ("Enter test score 2: ")
> tscore3 = input ("Enter test score 3: ")
> tscore4 = input ("Enter test score 4: ")
> tscore5 = input ("Enter test score 5: ")
Here the various scores are all strings. I recommend that you convert
them to int immediately:
tscore1 = int(input("Enter test score 1: "))
etc. That will avoid the problems you have below.
> total_tscore = int(tscore1) + int(tscore2) + int(tscore3) + int(tscore4) +
You add the scores as numbers. But the next line:
> low_tscore = min(tscore1,tscore2,tscore3,tscore4,tscore5)
you pick the score that comes first *as a string*, not as a number.
String comparisons are in lexicographic order:
"1000" < "9" because "1" comes before "9"
but 1000 > 9 because 1000 is a larger number.
So that's why you're getting unexpected results for the lowest score.
> adjusted_tscore = int(total_tscore) - int(low_tscore)
No need to convert total_tscore into an int, as it already is one.
> percent = int(adjusted_tscore/400*100)
This will truncate the percentages to the whole number part. That is, if
the percentage calculates as (say) 49.9999%, it will round down to 49,
rather than round to the nearest value 50.
Rather than int(), perhaps you should use round()?
Hope that helps!
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options: