213k views
2 votes
Write a Python program that requests five integer values from the user. It then prints one of two things: if any of the values entered are duplicates, it prints "DUPLICATES"; otherwise, it prints "ALL UNIQUE".

1 Answer

3 votes

Answer:
values = []

for i in range(5):

value = int(input(f"Enter value {i+1}: "))

values.append(value)

if len(set(values)) < len(values):

print("DUPLICATES")

else:

print("ALL UNIQUE")


Step-by-step explanation:

The program creates an empty list called values, and then uses a for loop to request five integer values from the user using the input() function. The int() function is used to convert the input values to integers, and the append() method is used to add each value to the values list.

After all five values have been entered, the program uses the set() function to create a set of the values. A set is an unordered collection of unique elements, so if there are any duplicate values in the original values list, they will be removed when the set is created. The program then compares the length of the original values list to the length of the set. If the lengths are not equal, it means there were duplicates in the original list, and the program prints "DUPLICATES". Otherwise, the program prints "ALL UNIQUE".

User Vivek Maskara
by
7.2k points