Jan-17-2023, 05:25 PM
(This post was last modified: Jan-17-2023, 05:25 PM by rob101.
Edit Reason: code error.
)
(Jan-16-2023, 11:39 AM)kafka_trial Wrote: This is very useful. Thank you.
Just one more question. How I would add the points for maths and history for each learners.
For example, let's say that Student John came fourth math which is 35 points and John came first in history which is 50 points. How could add these points.
Thanks.
PS: No, I don't know anything about dictionary yet. But I will learn asap.
You're welcome.
A Python
dictionary
is a very useful data construct, for which your use case could be:order = {"first": 100, "second": 95, "third": 90, "fourth": 85, "fifth": 80 }... and so on, but do you need that kind of thing? Why do you need that way of displaying the rankings?
I'd also like to better understand the points system, as it seems to be complicated. As an example, in your first post you said "... first place 100, second 95, third 90... so on.", but now you post "... let's say that Student John came fourth math which is 35 points and John came first in history which is 50 points."
A consistent scoring system would make the coding much simpler. For example, if there's always a 5 point separation between placements, then each place could be calculated by simply subtracting 5 points from 100 for each place. That would then make it quite easy to allocate points to each candidate, based on the position in the list:
# the data as entered, for example math = ['Paul', 'Ringo', 'John', 'George'] history = ['George', 'Ringo', 'John', 'Paul'] totals = [] name = 1 score = 0 for position, names in enumerate(math): math[position] = 100 - 5 * position, names math.sort(reverse=True) for position, names in enumerate(history): history[position] = 100 - 5 * position, names history.sort(reverse=True) print("Results for math:") for scores in math: print(f"{scores[name]}: {scores[score]}") print() print("Results for history:") for scores in history: print(f"{scores[name]}: {scores[score]}") for h_score in history: for m_score in math: if h_score[name] == m_score[name]: totals.append((h_score[score] + m_score[score], h_score[name])) totals.sort(reverse=True) print() print("Totals:") for scores in totals: print(f"{scores[name]}: {scores[score]}")
Output:Results for math:
Paul: 100
Ringo: 95
John: 90
George: 85
Results for history:
George: 100
Ringo: 95
John: 90
Paul: 85
Totals:
Ringo: 190
Paul: 185
George: 185
John: 180
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein