from datetime import datetime
from random import randint
def days_to_birthday(date):
datetime_object = datetime.strptime(date, "%Y-%m-%d")
date = datetime_object.date()
num_days = date.timetuple().tm_yday
return num_days
file_name = input("")
input_file = open(file_name , "r")
output_file = open("output.txt", "w")
year_list = []
for lines in input_file:
char_info = lines.split(" ")
char_name = char_info[0]
b_day = char_info[1]
bDay_list = b_day.split("-")
b_year = bDay_list[0]
num_of_days = int(days_to_birthday(b_day))
gender = char_info[2]
year_list.append(b_year)
count = year_list.count(b_year)
if gender == "F":
days = num_of_days + 500
else:
days = num_of_days
part_1 = b_year
part_2 = f'{days:03d}'
part_3 = f'{count:03d}'
ID_num = part_1+str(part_2)+str(part_3)
new_line = char_name, ID_num
output_file.write(str(new_line))
print(new_line[0], new_line[1])
when I give female info as the input it doesn't add that 500 I want it to. But when I input multiple female inputs on the row it adds the 500 to only the last female input
Here are the input file details I've used
Saman 1990-05-03 M
Kumaran 1988-03-05 M
Nazar 1997-09-24 M
Ravindu 2001-03-21 M
Nimasha 2001-08-10 F
Aruni 1990-04-06 F
Asha 2001-03-06 F