0
Why i can't see the number without duplication.
Why i can't see the number without duplication. import random def rand(): list=[] while len(list)<6: i=0 a=random.randrange(1,10) for i in range(len(list)): if a==list[i]: pass list.append(a) b=random.randrange(1,10) return list, b how i can see the another number without set, remove, in function? i want to check duplication number at [for] and after [while] i want to add number to list. what is the mistake?
10 odpowiedzi
+ 1
It sounds like you want a list with completely different numbers. This can be easily checked with:
if a not in list:
list.append(a)
Use this instead of pass! I’ve included a code you may use.
https://code.sololearn.com/c55423VpwNRo/?ref=app
+ 1
Look now, I think the problem was in your [for] loop. When the code first starts, your list doesn’t have any numbers. So when it first tries to loop over the length of the list, it stops because the range == 0. Add a random number to the list first, and then run your for loop!(:
https://code.sololearn.com/c55423VpwNRo/?ref=app
+ 1
I actually saw a bug, give me a second
+ 1
Works now!
+ 1
wow! i will try this after 30minutes!!
thank you for your teaching :) :D
+ 1
When I saw your code you had the b variable too, is that what you’re seeing as the duplicate? None of the numbers in the list are duplicated. I just took out the b variable. Check again(:
+ 1
oh I'm sorry. it works properly!!
wow thank you so much!!
you are genius :D
0
thank you so much :)
but it is [in] function. ㅠㅠ
my teaching assistant will not want to use that.
0
ok! thanks! i will try again :)
0
ㅠㅠㅠ it is also has duplication number