Sep-16-2017, 03:24 AM
(This post was last modified: Sep-16-2017, 03:24 AM by forumer444.)
How do you filter out the letters in the "all_years.txt" file?
I assume it goes in my appendFile() function.
Am I getting anywhere? :(
I took out the appendFile() function.
I assume it goes in my appendFile() function.
Am I getting anywhere? :(
I took out the appendFile() function.
# calculate function def leapYear(year): """ Calculates whether a year is or isn't a leap year. """ return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) # main function def main(): try: file = open("all_years.txt", "r") lines = file.readlines() for line in lines: if leapYear(int(line)): file2 = open("leap_years.txt", "w") print(file2.write(line)) except FileNotFoundError as e: print(e) main()