#! /Usr/bin/python #-*-coding: UTF-8-*-#8-2. loop. write a program that allows the user to input three numbers: (f) rom, (t) o, and (I) ncrement. # Take I as the step and count from f to t, including f and t. for example, if the input is f = 2, # t = 26, I = 4, the program will output 2, 6, 10, 14, 18, 22, 26.f = int (raw_input ("Please input from:") t = int (raw_input ("Please input to:") I = int (raw_input ("Please input increment: ") print range (f, t + I, I)
#8-2. range (). If we need to generate the following lists, which parameters need to be provided in the range () # built-in functions? # (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 (10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range (3, 19, 3) [3, 6, 9, 12, 15, 18] >>> range (-20,861,220) [-20,200,420,640,860] >>>
#! /Usr/bin/python #-*-coding: UTF-8-*-#8-4. prime number. in this chapter, we have provided some code to determine the maximum approximate number of a number or whether it is a # prime number. convert the code to a function with a Boolean value. The function name is isprime (). # If the input is a prime number, True is returned; otherwise, False is returned. import mathdef isprime (number): num = int (math. sqrt (number) while num> 1: if number % num = 0: return False num-= 1 else: return Trueprint zip (range (1, 12 ), (isprime (x) for x in range (1, 12 )))
#! /Usr/bin/python #-*-coding: UTF-8-*-#8-5. approx. complete a function named getfactors. it accepts an integer as a parameter, # returns a list of all its dikes, including 1 and itself. def getfactors (number): factorslist = [number] num = number/2 while num> 0: if number % num = 0: factorslist. append (num) num-= 1 return factorslist