36.5k views
1 vote
Write a program that reads in 10 numbers and displays the number of distinct numbers and the distinct numbers in their input order and separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). After the input, the array contains the distinct numbers. Here is a sample run of the program.

User Goonerify
by
3.9k points

1 Answer

1 vote

Answer:

Step-by-step explanation:

The following code is written in Python. It creates a for loop that iterates 10 times, asking the user for a number every time. It then checks if the number is inside the numArray. If it is not, then it adds it to the array, if it is then it skips to the next iteration. Finally, it prints the number of distinct numbers and the list of numbers.

numArray = []

for x in range(10):

num = input("Enter a number")

if int(num) not in numArray:

numArray.append(int(num))

print("Number of Distince: " + str(len(numArray)))

for num in numArray:

print(str(num), end = " ")

Write a program that reads in 10 numbers and displays the number of distinct numbers-example-1
User Shrikant Wandhare
by
3.2k points