Describe the difference between a chained conditional and a nested conditional. Give your own example of each.
Chained conditional is an if statement where a condition is executed if it is true but if it is false the next condition is checked and so on
Example
n=10
if n%2==0:
print("Even number")
elif n%2!=0:
print("Negative number")
else:
print("Invalid number")
Nested condition is a condition where an if statement is created inside another if statement.
example
n=10
if n%2==0:
if n>0:
print("Positive even number")
else:
if n<0:
print("Negative even number")
Comments
Leave a comment