Python Core Programming Second Edition eighth Chapter after class answer

Source: Internet
Author: User

Note: I use the python3.5. where range and Xrange,input and Raw_input have been merged

8-1. Conditional statements. Take a look at the following code:

# statement A
If x > 0:
# statement B
Pass
Elif x < 0:
# statement C
Pass
Else
# statement D
Pass
# statement E
(a) If x<0, which of the above statements (A,B,C,D,E) will be executed?
(b) If x=0, which of the above statements will be executed?
(c) If x>0, which of the above statements will be executed?

(a) ACE, (b) ADE, (c) ABE

8-2. cycle. Write a program that allows the user to enter 3 numbers: (f) ROM, (t) O and (i) ncrement. Take I as the step, counting from F to T, including F and T. For example, if you enter F = 2,t = 26,i = 4, the program outputs 2,6,10,14,18,22,26.

f = Int (input ('from='= Int ('to='= int (input ('increment=')) while F <= T-i    := f + I      Print (f)

8-3.range (). If we need to generate the following lists, do we need to provide those parameters in the range () built-in function, respectively?
(a) [0,1,2,3,4,5,6,7,8,9]
(b) [3,6,9,12,15,18]
(c) [-20,200,420,640,860]

Range (3,19,3) range (-20,861,220)

8-4. Prime numbers. We have given some code in this chapter to determine the maximum number of numbers or whether it is a prime. Please convert the relevant code to a function that returns a Boolean value with the function name IsPrime (). Returns true if the input is a prime number, or False if no is returned.

Slightly

8-5. Approximate. Complete a function named Getfactors (). It takes an integral type as a parameter, returns a list of all its approximations, including 1 and itself

Python Core Programming Second Edition eighth 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.