"while" loop - Re-execution of the program
Question: For starters I'll just say that I'm fresh Python programmer. I started writing
database client and I have problem. Perhaps this question for many will seem
silly, but for me as a rookie is it a problem.

I write main_module that adds data to the database I would like to after the
last condition, user have the possibility to add more data. Something like
that: repeat = input("Do you wanna create new record?(Y/N)") if repeat = Y:
(the program starts from the beginning) else: (Program close)

Where such a condition should be found?

Below is my code

    
    
    import sqlite3
    import time
    import datetime
    import sys
    
    conn = sqlite3.connect('template.db')
    c = conn.cursor()
    
    def create_table(): #
        c.execute("CREATE TABLE IF NOT EXISTS Theft(template1 TEXT, template2 TEXT, template3 TEXT, template4 TEXT, template5 TEXT)")
    
    
    def data_entry():
        unix = int(time.time())
        template1 = str(datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
    
        c.execute("INSERT INTO Theft(template1, template2, template3, template4, template5) VALUES (?, ?, ?, ?, ?)",
                    (template1, template2, template3, template4, template5))
    
        conn.commit()
    
    template2 = input("ENTER template ")
    template3 = input("ITEM template ")
    template4 = input("INPUT template ")
    template5 = input("INPUT YOUR template: ")
    
    accept = input("Do you wanna create new record in DB? (Y/N)")
    if accept == "y":
        create_table(), data_entry()
    elif accept == "Y":
        create_table(), data_entry()
    else:
        sys.exit(0)
    
    
    c.close()
    conn.close()
    

Regards Jmazure :)


Answer: You have to put your input procedure inside an infinite loop that will be
broken only if the user input something else than "y" or "Y":

    
    
    while True:
        accept = input("Do you wanna create new record in DB? (Y/N)")
        if accept.lower() == "y": <-- checks if accept =="y" or accept == "Y"
            create_table(), data_entry()
        else:
            break
    

