In python define a function float_range(start,stop,step): We define our own floa
ID: 3675469 • Letter: I
Question
In python define a function float_range(start,stop,step): We define our own floating-point version of range() here. It works the same as built-in range() function but can accept float values. Note: some floating point arguments will give you unexpected values due to the imprecision of floats in computer – you don’t need to worry about them as far as your algorithm is correct. o Assume: start, stop, and step are integer or float numbers. step is a non-zero value.
o Restrictions: you may not call range() .
(Plus, it only takes integer arguments).
Examples:
o float_range(0,1,0.25) [0,0.25,0.5,0.75]
o float_range(15.1,4,-2) [15.1,13.1,11.1,9.1,7.1,5.1]
o float_range(0,0.25,-1) []
Explanation / Answer
def float_range(start,stop,step) :
current = start;
list1 = []
if(step > 0) :
while ( current<=stop):
list1.append(current)
current = current + step
print list1
else :
while ( current>=stop):
list1.append(current)
current = current + step
print list1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.