title: Looping in Python 3
body: <p>This is my program. Any ideas on how I can make the whole thing loop, but only if the input is incorrect? I've already set a large integer for the range, but I can't figure out where and how to set the conditions to make it happen. Everything I've tried so far has given me an error. Any help would be greatly appreciated.</p>
  
  <pre><code>def main():
  
    for i in range(1000):
  
      date = (input("enter the date as dd/mm/yyyy: "))
  
      try:
          datetime.datetime.strptime(date,"%d/%m/%Y")
          print ("Format is Correct")
      except:
          ValueError
          print ("Format is Incorrect")
  
      date = day, month, year = date.split("/")
      if len(day) == 1 or len(day) == 2:
          day = int(day)
          if len(month) == 1 or len(month) == 2:
              month = int(month)
              months = ["emp", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
                        "Aug", "Sep", "Oct", "Nov", "Dec"]
              if len(year) == 4:
                  year = int(year)
                  if 1899 &lt; year &lt; 3001:
                      if year % 100 == 0:
                          if year % 400 == 0:
                              print ("It's a leap year")
                          else:
                              print ("It is not a lea[ year")
                      else:
                          if year % 4 == 0:
                              print ("It's a leap year")
                          else:
                              print ("It is not a leapyear")
                  else:
                      print ("The year is not in range")
                  if month &gt; 12 or month &lt; 0:
                      print ("The month is out of range")
                  elif month == 4 or month == 6 or  month == 9 or month == 11:
                      if day &gt; 30:
                          print ("The date is out of range for the month")
                  elif month == 2:
                      if day &gt; 29:
                          print ("The date is out of range for the month")
                  print(day, months[month], year)            
  
  main()
  </code></pre>