Short Circuit Practice


#Short circuit practice

x=6

y=2

print(x>=2and(x/y)>2)

#True

x=1

y=0

print(x>=2and(x/y)>2)

#False

x=6

y=0

print(x>=2and(x/y)>2)

#Calculation fails, causes runtime error as cannot divide by zero.

#Guard Evaluation

x=6

y=0

print(x>=2 and y!=0 and (x/y)>2)


True

False

Traceback (most recent call last):

  File "main.py", line 12, in <module>

    print(x>=2and(x/y)>2)

ZeroDivisionError: division by zero

Leave a comment

Log in with itch.io to leave a comment.