python, try ... excpet various methods of use

. 1 Print ( ' \ n-Welcome division calculator \ n-! ' )
 2  
. 3  the while True:
 . 4      the try :
 . 5          X = INPUT ( " Please enter your dividend: ' )
 . 6          Y = INPUT ( " Please enter the divisor: ' )
 . 7          Z = a float (X) / a float (Y)
 . 8          Print (X, ' / ' , Y, ' = ' , Z)
 . 9          BREAK   # counted only once per default, so here written BREAK .
10     except ZeroDivisionError: # when the divisor is zero, jump prompted to re-enter.
11          Print ( ' 0 divisor can not do! ' )
 12      the except ValueError: # when there is a divisor or the dividend can not be converted to floating point, popup prompt, re-enter.
13 is          Print ( ' divisor and dividend should be an integer or floating-point values! ' )
 14      
15      # 2 ways: the two (or more) abnormalities together, as long as a trigger which, on the implementation of the code included.
16      # the except (ZeroDivisionError, ValueError):
 17      # Print ( ' Your input is incorrect, please re-enter! ' )
 18      
19      # Mode 3: General error base class, assuming that do not want to provide a very fine tips, you can use this statement General error response.
20 is      # the except Exception:
 21 is      # Print ( 'Your input is incorrect, please re-enter! ' )

Guess you like

Origin www.cnblogs.com/Through-Target/p/12096740.html