Which of the following statement blocks should be used to catch the occurrence of a division by zero? do/while for/while if/else try/except
Thoughts about this one? As a major hint, division by zero will cause an error (exception) in the code. Which statement pair is used to catch exceptions?
Okay so from what i know division is used to find the quotient so for example 15 and 2 the result would be 7.5
So i don't even think do/while is a thing for option A so maybe B.)?
Keep in mind the problem is asking about how to handle the exception when you divide by 0 and get an undefined number. If you just set it up to do division, a person could enter 1 / 0 in which case the program will throw an exception. Therefore, you need to use a try/except clause, in order for your program to handle cases where the user divides by 0. For example, you could make the except statement print a message like “you cannot divide by zero” and then go back to the original division prompt for the user to try again.
Okay so the answer is D.) try/except
Join our real-time social learning platform and learn together with your friends!