Python Core Programming Second Edition tenth Chapter after class answer

Source: Internet
Author: User
Tags integer division

10.1

Throws an exception. Which of the following causes an exception to be thrown when the program executes? Note that we're not asking for exceptions here.

The reason.

a) users;

b) interpreter;

c) procedures;

D) all of the above;

(e) only B) and C);

f) only a) and C)

F

 

10-2. Throws an exception. Referring to the list of top issues, what factors throw an exception when the interaction interpreter is executed?

F

  

10-3. Keywords. What are the keywords that are used to throw exceptions?

Raise

  

10-4. Keywords. What's the difference between try-except and try-finally?

Try-except: When the try code block runs in error, the except code block will be executed (matching to the corresponding exception), after processing the exception after the Try-except code will continue to execute;

Try-finally: Eventually executes the code in finally, regardless of whether the try code block has an exception. If an exception occurs, the exception continues to be thrown at the top after the finally code block is executed.

i = 1try:    = 10%iexcept:    print('except  ')try:    = 10%ifinally:     Print('finally')
Output: Finally

10-5. Exceptions. What exceptions will be thrown by the Python code snippet below these interaction interpreters (see the list of built-in exceptions given in Table 10.2):

(a) >>>if 3 < 4 Then:print ' 3 is less than 4! '

(b) >>>alist = [' Hello ', ' world ', ' anyone ', ' Home ']

>>>print ' The last string of alist is: ', Alist[len (alist)]

(c) >>>x

(d) >>>x = 4 0

(e) >>>import Math

>>>i = math.sqrt (-1)

(a) Syntaxerror:invalid syntax (b) indexerror:list index out of range (c) nameerror:name ' x ' are not defined (d) zerodivisi Onerror:integer division or modulo by zero (e) Valueerror:math domain error

  

10-6. Improved open (). Create a wrapper for the built-in open () function. Causes the file handle to be returned when the file is successfully opened: If Open fails, it is returned to the caller none, instead of generating an exception. This way you can open the file without the need for additional exception handling statements.

Python Core Programming Second Edition tenth Chapter after class answer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.