Ask your own question, for FREE!
Computer Science 9 Online
kekeman:

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

Vocaloid:

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?

kekeman:

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

kekeman:

So i don't even think do/while is a thing for option A so maybe B.)?

Vocaloid:

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.

kekeman:

Okay so the answer is D.) try/except

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!