Write a python program which accepts 6 integer values and prints "DUPLICATES" if any of the values entered are duplicates otherwise it prints "ALL UNIQUE".
Answers
Answered by
7
Solution.
The given code is written in Python.
print('Enter 6 numbers..')
a=list()
for i in range(6):
a.append(int(input('Enter: ')))
if len(set(a))!=len(a):
print('DUPLICATES.')
else:
print('Unique.')
Explanation.
- In Python, set stores unique values.
- Here, we are checking whether the length of the set of numbers and the length of the list are equal or not.
- If they are equal, there is no repetition of values or else, there are duplicates present in the list.
A shorter approach for this problem -
print('Enter 6 numbers..')
a=list()
for i in range(6):
a.append(int(input('Enter: ')))
print(['Unique.','DUPLICATES.'][len(set(a))!=len(a)])
See attachment for output.
Attachments:
Similar questions