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