How to make a loop of nested if-statements to find the smallest number of something? I'm a beginning programmer and wrote a little code for a mathematical question. There are 6 rounds where each time the pile of cupcakes is divided into five equal groups, with one extra cupcake (which is discarded). Then one fifth is taken away and the next round starts. I've written the code, but there must be a way to write this shorter, a loop instead of nested if-statements.
My code:
 import sys

getal = 1

while True:
    if getal % 5 == 1:
        a = (getal - 1)/5
        if (a*4) % 5 == 1:
            b = (a*4-1)/5
            if (b*4) % 5 == 1:
                c = (b*4-1)/5
                if (c*4) % 5 == 1:
                    d = (c*4-1)/5
                    if (d*4) % 5 == 1:
                        e = (d*4-1)/5
                        if (e*4) % 5 == 1:
                            print(getal)
                            sys.exit()
                        else:
                            getal = getal + 1
                    else:
                        getal = getal + 1
                else:
                    getal = getal + 1
            else:
                getal = getal + 1
        else:
            getal = getal + 1
    else:
        getal = getal + 1
        continue

Thanks in advance!
PS: getal is Dutch for number (the number of cupcakes at the start, which is the result of my question).
I'm not sure what your code is doing. As it currently stands, it will print the first number that satisfies the requirement of being composed of various parts, all divisible by 5 with a remainder of 1.
If that is your objective, then you should certainly compute the number as an equation: (0*5)+1 *5 ... etc.
If you are working up to determining whether any given number meets the condition, then you can certainly continue as you are doing.
Here are some tips to improve your efficiency and clarity:

Get rid of the continue at the bottom of the loop. It is not needed.

Get rid of the various statements getal = getal + 1 in your else branches. By inspection, I can see that this adjustment is always done whenever you loop (since you sys.exit() on success) so just move the statement to the top of the loop, and adjust your incoming variable:
 getal -= 1
 while True:
     getal += 1
     # many, many if statements


Perform your multiplication as part of your adjustment to getal, not as a separate part of your if statements:
 a = ((getal - 1) / 5) * 4
 if a % 5 == 1:


Consider negating your tests. Instead of looking for &quot;good&quot; values, look for &quot;bad&quot; values. Because you are testing for &quot;failure,&quot; and because the response to failure is to jump away (continue), you can replace nesting with a series of tests at the same level:
 if a % 5 != 1:
     continue
 b = ...
 if b % 5 != 1:
     continue
 c = ...
 if c % 5 != 1:
     continue