python / beginner
Snippet
Conditional Logic
If-statements allow your code to make decisions. The elif (else if) and else clauses provide alternative paths based on different conditions.
snippet.py
1
2
3
4
5
6
7
score = 85if score >= 90:print("Excellent!")elif score >= 70:print("Good job!")else:print("Keep practicing!")
Breakdown
1
if score >= 90:
Checks if the score is 90 or higher.
2
elif score >= 70:
Checks a second condition if the first one was False.
3
else:
Executes if none of the above conditions were met.