Allot a stream from marks
Write a Python program that allots a stream: marks above 85 Science, above 70 Commerce, 35 to 70 Arts, below 35 Fail.
88, 72, 50, 20
88 -> Science 72 -> Commerce 50 -> Arts 20 -> Fail 70 -> Arts 35 -> Arts
Approach
- Test from the highest band down so every mark lands in exactly one stream.
Solution
def stream(marks): if marks > 85: return "Science" elif marks > 70: return "Commerce" elif marks >= 35: return "Arts" else: return "Fail" for m in [88, 72, 50, 20, 70, 35]: print(m, "->", stream(m))88 -> Science 72 -> Commerce 50 -> Arts 20 -> Fail 70 -> Arts 35 -> Arts
Line by line
Using >= for 35 and falling through from the band above means boundary values such as 70 and 35 are covered. The original ranges (35 < marks < 70) left 35 and 70 with no stream.
Learn the concept
New to this topic? Read the lesson, then come back.