Python Conditionals and Loops
Python Conditionals and Loops
In this example, since age is 20 (which is greater than 18), the condition
evaluates to true, and the message is printed
if-else
Here, since age is 16 (which is less than 18), the condition is false, and the
else block executes.
If-elif statement
In this case, marks is 85, so the first condition is false, but the second
condition (marks >= 80) is true, assigning grade 'B'.
Loops in Python
In this example, count starts at 1 and increments by 1 each time the loop runs
until it exceeds 5
for Loop