#! /usr/bin/python3 # =================================================================== # Leap Year calculation # =================================================================== import user_interface as ui # ---- test for a leap year def is_a_leap_year(n): if n%4 > 0: return False if n%100 > 0: return True if n%400 > 0: return False return True # ---- display the game description def program_description(): ui.clear_screen() print('---------------------- Leap Year ----------------------') print('This program determines whether a year is a leap year') print('or a common year in the Gregorian calendar (and in the') print('proleptic Gregorian calendar before 1582).') # ------------------------------------------------------------------- # ---- main # ------------------------------------------------------------------- program_description() while(True): # ---- ask the user for year print() s = ui.get_user_input('Enter a year: ') # ---- empty string? if not s: break # ---- verify input tf,n = ui.is_int(s) if not tf: print(f'Illegal value entered - try again') continue if n < 0: print(f'Illegal value entered - try again') continue # ---- test for leap year print() if is_a_leap_year(n): print(f'{n} is a leap year') else: print(f'{n} is not a leap year') print()