lundi 19 avril 2021

Python why we cant random decimal values [closed]

My Code:

import random
randomlist = []
for i in range(0,100):
    n = random.randint(1.0,2.0)
    randomlist.append(n)
print(randomlist)

From Above Code :

n = random.randint(1.0,2.0)

Its Correct

But When

n = random.randint(0.1,1.0)
n = random.randint(0.001,1.001)

Gives An Error

> Traceback (most recent call last):   File
> "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py",
> line 31, in <module>
>     start(fakepyfile,mainpyfile)   File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py",
> line 30, in start
>     exec(open(mainpyfile).read(),  __main__.__dict__)   File "<string>", line 4, in <module>   File
> "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/random.py",
> line 248, in randint
>     return self.randrange(a, b+1)   File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/random.py",
> line 212, in randrange
>     raise ValueError("non-integer arg 1 for randrange()") ValueError: non-integer arg 1 for randrange()

[Program finished]

How Its Possible?




Aucun commentaire:

Enregistrer un commentaire