Describe the difference between a chained conditional and a nested conditional. Give your own example of each. Do not copy examples from the textbook.
x, y = 1, 0
#chained conditional
if x > y:
print('x bigger than y')
elif y > x:
print('y bigger than x')
else:
print('x = y')
#nested conditional
if x > y:
print('x bigger than y')
else:
if y > x:
print('y bigger than x')
else:
print('x = y')
The difference between a chain of conditions and nested conditions is that only one condition is fulfilled in the chain of conditions, and the chain of conditions is branching and several conditions can be fulfilled.
Comments
Leave a comment