+ 3
I don't understand this error
9 Respuestas
+ 7
here is the reworked code:
- corrected index calculation
- removed multiple import of random
https://code.sololearn.com/cSd8Gi01M9Ip/?ref=app
+ 7
Royalx , i saw that is working now. Great! 👍
+ 6
Royalx , you need to post the code here. best way is to put it in playground and then link it in your post. without having seen the complete code, everything is a guess. Thanks!
+ 5
I tried using this and it worked when the index is less than len(av) but is out of range when it equals len.
It will work if you say len(av)-1
https://code.sololearn.com/cZMsz69GJ5Yn
or just use print(r.choice(av))
+ 3
Royalx
Simple example:-
Consider a list of length 5
List=[4,5,7,8,6]
Pos- 0 1 2 3 4
your function/program calling list value of index/pos less than 0 or greater than 4 (ex:- List[6]).
+ 3
Thanks :)
+ 1
This mean that the index given as input to av list is great than its lenght if there are 5 element in your av list so r.randint(0,len(av)) will generate a number great than 5 .
+ 1
import random as r
for i in range(10):
print(r.randint(0,5))
Prints number 5 as well,so you need to pass len(av)-1 as second argument to randint