91.0k views
3 votes
Write a program that asks the user to enter a list of numbers. The program should take the list of numbers and add only those numbers between 0 and 100 to a new list. It should then print the contents of the new list. Running the program should look something like this:

Please enter a list of numbers: 10.5 -8 105 76 83.2 206

The numbers between 0 and 100 are: 10.5 76.0 83.2

1 Answer

5 votes

In python 3.8

nums = input("Please enter a list of numbers: ").split()

new_nums = [x for x in nums if 0 < float(x) < 100]

print("The numbers between 0 and 100 are: " + " ".join(new_nums))

When you said numbers between 0 and 100, I didn't know if that was inclusive or exclusive so I made it exclusive. I hope this helps!

User RJM
by
4.9k points