Simple exception handling example,exceptionhandling,number1 = ra
文章由Byrx.net分享于2019-03-23 06:03:26
Simple exception handling example,exceptionhandling,number1 = ra
number1 = raw_input( 'Enter numerator: ' )number2 = raw_input( 'Enter denominator: ' )try: number1 = float( number1 ) number2 = float( number2 ) result = number1 / number2# float raises a ValueError exception except ValueError: print 'You must enter two numbers'except ZeroDivisionError: print 'Attempted to divide by zero'else: print '%.3f / %.3f = %.3f' % ( number1, number2, result )
相关内容
- Demonstrates handling exceptions,,# try/except
- Power calculation,powercalculation,print 2L **
- Print rounds,printrounds,num = 1 / 3.
- Start 10 copies of a function running in parallel,copiesparallel,im
- Serialized by the mutex lock,serializedmutex,import threa
- Getting Child Nodes,gettingchildnodes,from xml.dom
- Child Nodes Can Be Text,childnodes,from xml.dom
- Searching Is Actually Recursive,searchingrecursive,from xml.dom
- Parsing XML from a URL,parsingxml,import urlli
- Parsing XML from Strings,parsingstrings,from xml.dom
评论关闭