what time it takes to printing all 6 digit numbers in python?

Sorry, I searched it in google but didn’t find the expected result. Please help. It is very important. My code for printing this:

for i in range(100000,1000000):
print(i)

It is a simple code. I just have to know what time it takes to complete the printing. Did anyone try it before? Did anyone try to print all 6 digit number? if yes, please help. I am practically doing it but in my old and slow computer it stuck.

In python it might be a bit slower, but I am talking in a general view. In Python I guess it should be O(3 * 10^6). But I have no clue as I don’t code in python.

The computer does ~10^8 operations a second. So it will get processed within a second, but to output those many numbers, it will take time in the terminal.

But when I tried to solve this, I wait 30 minutes but it didn’t give me any output. At last, it gave me a Memoryerror.

s3 = []
s = []
s5 = []
for i in range(100000,1000000):
a = str(i)
li = list(a)
s1 = int(li[0])+int(li[1])+int(li[2])+int(li[3])+int(li[4])+int(li[5])
s2 = int(li[0])*int(li[1])*int(li[2])*int(li[3])*int(li[4])*int(li[5])
k = 1
for _ in range(100000):
a = s1%k
b = s2%k
if a == 0:
s.append(a)
if b == 0:
s5.append(b)
k = k + 1
if len(s) == 2 and len(s5) == 2:
s3.append(i)
print(s3)

P S: I was trying to solve this problem- How many numbers are there which contain six digits and the sum and product of the digits are both prime numbers?

Why are you even iterating through all possible numbers. Since you want the product of six digits of the number to be prime, then it is only possible if there are 5 1’s in the number and a 1 digit prime number as the sixth number. i.e possible numbers are.
1 1 1 1 1 2 : sum = 7
1 1 1 1 1 3 : sum = 8
1 1 1 1 1 5 : sum = 10
1 1 1 1 1 7 :sum = 12
hence six numbers with sum and product as prime numbers are 1 1 1 1 1 2
and there are a total of 6!/(5!*1!) i.e 6 permutations hence shouldn’t the ans just be 6 , please correct me if I am wrong anywhere

I’m using Cygwin (which I highly recommend for Windows users) which provides me with the time command to calculate the time taken by a command.

I stole a look at the image you just deleted and came to know that you’re using the cmd of a Windows 7. In case you don’t feel like downloading Cygwin (which is totally fine ) you may use the equivalent for timing a command, i.e., the Measure-Command command available in the PowerShell which you already have on your system.

I just used it on your script with a tiny modification because it was taking up too much time.