How to make a program that infinitely sends a message after reaching a certain point

Viewed 64

So I want to make a program that increases in 'count'. Every interval of 1 000 000, I want the program to say: "(1),000,000" marked has been reached. Of course I want that (1) to be replaced with 2, 3, 4, 5, 6 etc, whenever the interval has been reached. So when the two million mark has been reached I want it to say "2,000,000" mark has been reached."

Here is a simplified version of what my program is doing. However it is fixed to the intervals that I have set.

count = 0 

while True:
    count += 1
    if count == 1000000:
        print("The 1000000 mark has been reached.")
    if count == 2000000:
        print("The 2000000 mark has been reached.")
    if count == 3000000:
        print("The 3000000 mark has been reached.")
3 Answers

Try the following with a modulus operator:

count = 0 

while True:
    count += 1
    if count % 1000000 == 0:
        print(f"The {count} mark has been reached.")

For an explanation about the modulus (%) operator, see this article

You can use the modulo operator:

count = 0

while True:
    count += 1
    if count % 1000000 == 0:
        print(f"The {count} mark has been reached.")

See if this one can help you:

Var, Count = 0, 1000000

while True:
    Var += 1
    #print(Var)
    if Var == Count:
        Count += 1000000
        Var1 = str(Var).find("0")
        Value = str(Var)[:Var1]+","+str(Var)[Var1::]
        print(f"The {Value} mark has been reached")
Related