So I'm starting to learn Python (3.43) code on my own time and my friend who is a major in Comp Sci made up a little assignment for me to try to complete although I have no class experience. So what I need to do is make some code where the user is prompted to input how many scores to be entered and for hose to be inputed on each line which i have successfully completed. The hard part is figuring out how to make the min, max, and avg work into this. This is my cide thus far:

def scores():
        print('we are starting')
        count = int(input('Enter amount of scores: '))
        print('Each will be entered one per line')
        scoreList = []
        for i in range(1, count+1):
                scoreList.append(int(input('Enter score: ')))
                print(scoreList)
        print(scoreList)
        print('thank you the results are:')
        mysum = sum(count)
        # mysum needs to be a float
        average = 1.0*mysum / count
        print ('Total: ', str(count))
        print ('Average: ', str(average))
        print ('Minimum: ', str(min(count)))
        print ('Maximum: ', str(max(count)))
scores()

While a direct answer is helpful, I'd really like to understand what it is I may be doing wrong or some pointers on how to make it better. I understand my code skills are elementary but I'm trying to grasp the basics without paying a large amount for a class. I do however plan on taking a course once I can grasp the basics. thank you!

Recommended Answers

All 2 Replies

Have two extra variables. Call them min and max.
Give min initially an impossible "high" value, say 999.
Give max initially an impossibl "low" value, say -1.
Now after every input of a score, compare that score to min and max.
Use lower than for min and higher than for max.
After input of all scores min should contain the lowest score and max the highest.
Success!

You must call the min() and max() functions with the argument scoreList instead of count. The same holds for sum()

print ('Minimum: ', str(min(scoreList)))
print ('Maximum: ', str(max(scoreList)))

You can also improve the input part:

scoreList.append(int(input('Enter score {:d}/{:d}: '.format(i, count))))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.