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

13th Sep 2021, 5:27 AM
Hamid
3 Réponses
+ 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=' ')
13th Sep 2021, 6:33 AM
Python Learner
Python Learner - avatar
+ 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))
13th Sep 2021, 5:38 PM
iTech
iTech - avatar
+ 1
thanks a lot
13th Sep 2021, 6:13 PM
Hamid