Attendance is a string of P and A per student for 10 days. Print each student's attendance percentage, the students below 75%, and on which day numbers everyone was present.
names = ["Asha", "Ravi", "Meera"]
records = ["PPPPAPPPPP", "PAPAPPAPPA", "PPPPPPPPPP"]
for name, rec in zip(names, records):
print(f"{name:<6}{rec.count('P') / len(rec):.0%}")
print("below 75%:", [n for n, r in zip(names, records) if r.count("P") / len(r) < 0.75])
print("full days:", [day for day, marks in enumerate(zip(*records), 1) if all(m == "P" for m in marks)])
Output Verified by running it on Python 3
Asha 90%
Ravi 60%
Meera 100%
below 75%: ['Ravi']
full days: [1, 3, 6, 8, 9]
zip(*records) gives each day's marks across students; enumerate numbers the days from 1 and all() checks that everyone was present.
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!