Computer Science, asked by mitalibakle1301, 26 days ago

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 anindyaadhikari13
7

Solution.

The given co‎‎de is written in Python.

\rule{300}{2}

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.')

\rule{300}{2}

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