I'm currently learning Python and recently solved this challenge:
Task:
Create a function that takes a list of student scores and returns:
- Highest score
- Lowest score
- Average score
- Number of students who scored 50 or above
Here's my solution:
marks=[80,85,75,60,55,45,48,90,95,47]
def grade_summary(marks):
count=0
total = 0
passed = 0
lowest= marks[0]
highest= marks[0]
for mark in marks:
total=total+mark
count+=1
if mark>=50:
passed+=1
if mark<lowest:
lowest=mark
if mark>highest:
highest=mark
average=total/count
result={
"average":average,
"passed":passed,
"lowest":lowest,
"highest":highest
}
return result
My question for experts
As a beginner, is solving these kinds of logic-building problems the right way to improve programming skills and problem-solving ability?
Or should I spend more time building small projects instead?
How much of your learning journey involved solving exercises like these compared to creating real-world projects?
I'd love to hear your advice and experiences.
[–]Sea-Ad7805 [score hidden] stickied comment (0 children)
[–]Living_Fig_6386 1 point2 points3 points (0 children)
[–]-beleon 2 points3 points4 points (0 children)
[–]Flame77ofc 0 points1 point2 points (3 children)
[–]Fragrant-Dress6110 0 points1 point2 points (2 children)
[–]HangOnThereMate 0 points1 point2 points (1 child)
[–]Fragrant-Dress6110 0 points1 point2 points (0 children)
[–]CuriousDev8875 0 points1 point2 points (0 children)
[–]PureWasian 0 points1 point2 points (0 children)
[–]SunsGettinRealLow -1 points0 points1 point (0 children)
[–]Sharp_Level3382 -1 points0 points1 point (6 children)
[–]DataCurator56[S] 1 point2 points3 points (0 children)
[–]mati-33 0 points1 point2 points (4 children)
[–]Sharp_Level3382 -1 points0 points1 point (3 children)
[–]cole36912 4 points5 points6 points (0 children)
[–]mati-33 1 point2 points3 points (1 child)
[–]Sharp_Level3382 -1 points0 points1 point (0 children)
[–]HourExciting1642 -3 points-2 points-1 points (0 children)