Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 10 - Lists - Programming Exercises - Page 350: 10.5

Answer

code

Work Step by Step

# 10.5 (Print distinct numbers) Write a program that reads in numbers separated by a # space in one line and displays distinct numbers (i.e., if a number appears multiple # times, it is displayed only once). (Hint: Read all the numbers and store # them in list1. Create a new list list2. Add a number in list1 to list2. # If the number is already in the list, ignore it.) n = input("Enter ten numbers: ") l1 = [int(x) for x in n.split()] l2 = [] for x in l1: if x not in l2: l2.append(x) print("The distinct numbers are:",l2)
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.