Share your repls and programming experiences

← Back to all posts
How to make a list 'count' to 1000
madmonster (33)

First, you have to import random and time.
When you have finished, type in time.sleep(5)
We're using this to prevent a sudden crash.
You should now type in print(list(range(1,1000))) as your final line.
Your program should look like this:

Nanashi (7)

If your system is literally crashing after importing modules without the use of time.sleep(1), something's wrong. And what is random for? If this post isn't a joke, it is nonsensical, to put it bluntly. The script doesn't even match what the text is saying.

What is range()? It is an object representing an immutable sequence of integers but isn't a list. list() converts an iterable into a list. So we have: print(list(range(1,1001))).

Another way to create a list of numbers 1-1000 is to use a for loop and append() each number (adds an item to the end of a list):

a = []
for i in range(1, 1001):

# Single line print statement
print(list(i for i in range(1,1001)))

I can imagine the use of time.sleep() to have the console "count" to 1000, printing one number at a time:

import time

for i in range(1, 1001):

NOTE: Ctrl + C to stop (if not using's stop button).

a5rocks (826)

@Nanashi There are even couple other ways! Let me list a couple :

 def f(x):
  if x == 1000:
    return 1000
  return [x]+list(f(x+1))

[i for i in range(1, 1001)]

madmonster (33)

@Nanashi Thank you for reporting the advice!!!!!!!!!!!!!!!!!!!!