Here is a functional approach, as alluded to by @Peilonrayz:
def get_numbers_up_to(n, min_=10):
"""
Ask the user for numbers until he enters a number larger than `n`.
Yields all entered numbers larger than `min_`.
"""
while True:
try:
num = int(input())
except ValueError:
continue
if num > n:
break
elif num >= min_:
yield num
if __name__ == '__main__':
print('\n'.join(map(str, get_numbers_up_to(100)))
This uses a generator function to yield
the numbers as they come in (if they match the criteria), instead of accumulating them in a list right away.
Instead of '\n'.join(str(value) for value in lst)
this uses '\n'.join(map(str, lst))
, but this is a matter of taste in Python 3.x (if you like functional programming more, the map
looks nicer).
Other than that, your code does not include any user input validation. (What happens if the user inputs foo
, instead of a number?)
Also, all values are hard-coded, so re-using the code becomes harder. Therefore I made it into a function with parameters.
Note that I used min_
instead of min
to avoid shadowing a built-in function.
Also, docstrings never hurt nobody.
I also included a if __name__ == '__main__':
guard to allow importing of this function from another module.