+ 1

Help pls

Hi everyone, I am trying to make a random number picker. Overall it’s working fine, no bugs or anything but It only works with integers. Can someone tell how can I make this work with floats? https://code.sololearn.com/cy8X2rerpqL1/?ref=app The code is here!

7th Sep 2018, 4:22 PM
ron avni
ron avni - avatar
3 Answers
+ 6
import random import numpy as np print(random.choice(np.arange(1, 2, .1))) #You can use this or implement your range function #(numpy is not builtin)
7th Sep 2018, 4:41 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 5
random.choice returns random item from non empty sequence numpy.arange returns an 'ndarray' (numpy.array) and works like 'range' but parameters can be floats
7th Sep 2018, 4:53 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 1
wow thank you so much but can u explain to me what every line means?
7th Sep 2018, 4:44 PM
ron avni
ron avni - avatar