Код: Выделить всё
"""
Trying to add elements in a array without any duplicates(as per a given range n).
As soon as a dup no comes up, i can add only upto n-1 range while avoiding the dup element entered.
"""
arr = []
a = int(input('Enter a range: '))
for i in range(a):
i = int(input())
if i in arr:
print('its a dupl,enter another')
continue
else:
arr.append(i)
print(arr)
Код: Выделить всё
##############
Enter a range: 6
1
2
3
8
9
1 ---> 'the dup ele'
its a dupl,enter another
[1, 2, 3, 8, 9]----> can only enter 5(ie n-1 range)
Как я могу гарантировать наличие в массиве полных 6 недублированных элементов.< /p>
я пробовал
Код: Выделить всё
not in
Код: Выделить всё
break
используется далее:
Код: Выделить всё
i = int(input())
а зря.
Подробнее здесь: https://stackoverflow.com/questions/791 ... en-range-n