Question

My program runs and once it prints the final statement it immediately exits.

How can I pause the program for about 3 seconds so the user can read the output and then have the program return to the beginning of the program, or just return it to the original variable/question (the date question)?

def main():
    date = input("""Please enter today's date (mm/dd/yy): """)
    print()
    date_list = date.split('/')

    month_validate(date,date_list)

    day_validate(date,date_list)

    year_validate(date,date_list)

    long_date(date,date_list)

    ################################################

    def long_date(date,date_list):
    month = int(date_list[0])
    day = int(date_list[1])
    year = int(date_list[2])
    print(date,' has been accepted \n')

    while month >= 1 and month <= 12:
        if month == 1:
            print('Date: January',day,',',year)
            return date
        elif month == 2:
            print('Date: February',day,',',year)
        elif month == 3:
            print('Date: March',day,',',year)
        elif month == 4:
            print('Date: April',day,',',year)
Was it helpful?

Solution 2

Use the time.sleep(seconds) function.

import time
#where you want to pause
time.sleep(3)
#then if you want to restart at the begnining:
main()

OTHER TIPS

As your program seems to be already encapsulated in a main function, instead of just calling it once, you basically just have to keep running it in a loop:

while True:
    main()

    # sleep here, or maybe ask the user if they want to repeat
    time.sleep(3)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top