I’m new at programming and i need help with my “work”. I need to print specific number from a list. List = from 1 to 10 000 and i need to pick every single number that has “375” as a last three digits For example: 375, 1375, 2375 etc. My english isn’t the best so I hope you undestood me right. Thank you for your help.
enter image description here I know that that “random” shouldn’t be there but i don’t know what to do anymore
Advertisement
Answer
You can use a comprehension:
>>> [i+375 for i in range(0, 10000, 1000)] [375, 1375, 2375, 3375, 4375, 5375, 6375, 7375, 8375, 9375]
A more generic way:
number = 375 start = 0 end = 10000 step = 10**len(str(number)) lst = [i+number for i in range(start, end, step)] print(lst) # Output [375, 1375, 2375, 3375, 4375, 5375, 6375, 7375, 8375, 9375]