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?

19th May 2018, 11:08 AM
park
10 ответов
+ 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
19th May 2018, 12:23 PM
Nathan Lewis
Nathan Lewis - avatar
+ 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
19th May 2018, 1:08 PM
Nathan Lewis
Nathan Lewis - avatar
+ 1
I actually saw a bug, give me a second
19th May 2018, 1:13 PM
Nathan Lewis
Nathan Lewis - avatar
+ 1
Works now!
19th May 2018, 1:27 PM
Nathan Lewis
Nathan Lewis - avatar
+ 1
wow! i will try this after 30minutes!! thank you for your teaching :) :D
19th May 2018, 1:29 PM
park
+ 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(:
19th May 2018, 1:37 PM
Nathan Lewis
Nathan Lewis - avatar
+ 1
oh I'm sorry. it works properly!! wow thank you so much!! you are genius :D
19th May 2018, 2:01 PM
park
0
thank you so much :) but it is [in] function. ㅠㅠ my teaching assistant will not want to use that.
19th May 2018, 12:46 PM
park
0
ok! thanks! i will try again :)
19th May 2018, 1:13 PM
park
0
ㅠㅠㅠ it is also has duplication number
19th May 2018, 1:35 PM
park