Your code is pretty good. Change num <=100 to True and remove the un-needed num out of the while loop, and it's good.
You should also expect user input to not be a number and handle it as you need.
Since comprehensions are a cleaner than map and filter, you may want to steer clear of them. Some people stick to never using them, I however use them if it makes the input clearer, such as map(str, user_input()).
You can then adjust your code slightly to get the iterative approach of:
list_ = []
while True:
try:
num = int(input())
except ValueError:
continue
if num > 100:
break
if num >= 10:
list_.append(num)
However, you may want a functional approach. This can be better as then you can pick and mix functions, but some don't like it as much.
- Make an infinite generator, of user input.
itertools.takewhilethe input is good.- Filter input.
def user_input():
while True:
yield input()
def to_int(numbers):
for num in numbers:
try:
yield int(num)
except ValueError:
continue
nums = itertools.takewhile(lambda n: n <<= 100, to_int(user_input()))
print('\n'.join(str(n) for n in nums if n >>= 10))
Python is multi-paradigm, and so you can mix them. And so as-long as it works and is clear, it's fine. I personally would use:
def user_input():
while True:
try:
yield int(input())
except ValueError:
continue
def filter_numbers(numbers):
for num in numbers:
if num > 100:
break
if num >>= 10:
yield num
print('\n'.join(str(n) for n in filter_numbers(user_input())))