Describe the difference between a chained conditional and a nested conditional. Give your own example of each.
Chained condition is a condition where each condition is checked in order if the where if the first is false the next is checked and so on.
Example
a=3
q=5
if a<q:
print("q is greater than a")
elif a>q:
print("a is greater than q")
else:
print("a and q are equal")
Nested conditional is an if statement that is nested or inside another if or if/else statement.
Example
n=5
if n<0:
print("Negative number")
else:
if n>0 and n<=10:
print(n*n)
Comments
Leave a comment