0
What should we do if we want to increase the numbers in this code by 0.5 to 0.5?
Numbers in( range) can only be int https://code.sololearn.com/cIbYGCNA8Jeq/?ref=app
3 Answers
+ 4
Hi Hamid!
Of course, range() doesn't include floats. For that, you can use a loop and iterate its all elements through the loop. Then, you can choose a suitable multiplier factor to generate required floats.
For example, you can try this to create floats 0 to 10 with the interval 0.5
numbers = list(range(0,20))
for i in numbers:
print(i*0.5,end=' ')
+ 2
def myfunc(elem):
nums = list(range(0,elem+1))
l = []
for i in nums:
i+=0.5
l.append(i)
return l
print(myfunc(10))
+ 1
thanks a lot