1

I have tried using a while True statement to repeat asking the question but that just kept spamming the question to the user which was pretty entertaining albeit not very useful.

https://pastebin.com/8pshcZWm

gen_model = input('Shall we start the missile code generator?')
if gen_model == 'yes':
    base = input("What 8 digit base number would you like to start on?  ") # This is the starting number.
    if len(base) > 8.1 or len(base) < 7.9:
        print("Please enter an 8 digit number.")
    else:
        end_no = input("What 8 digit number would you like to stop at?  ") # This is the end number.
        start_digits = "CODE"
        while True: # while True is always a True statent, similar to while 1==1.
            base = (int(base) + 1) # The amount you want to add on to starting number.
            print(start_digits + str(base), file=open("SecretCodes.txt", "a")) # str(base) converts the base number to string as you cant do string + integer.
            if base > (int(end_no)):  # This is the number you want it to stop at.
                break # Gets us out of the infinite loop.
KaliNoob2
  • 21
  • 3
  • 1
    Does this answer your question? [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – pppery May 02 '20 at 04:22

1 Answers1

0

Change this to

if len(base) > 8.1 or len(base) < 7.9:
        print("Please enter an 8 digit number.")

this

while len(base) != 8:
    print("Please enter an 8 digit number.")
    base = input("What 8 digit base number would you like to start on?  ")
deadshot
  • 8,881
  • 4
  • 20
  • 39