I have a text file named headerValue.txt which contains the following data:-
Name Age
sam 22
Bob 21
I am trying to write a python script that would add a new header called 'Eligibility'. It would read the lines from the text file and check if the age is more than 18, then it will print 'True' underneath 'Eligibility' header and also add one more header named 'Adult' and print a 'yes' underneath and 'no' if the age is less than 18.
Since in the text file the age of both is more than 18. The output will something be like:-
Name Age Eligibility Adult
sam 22 True yes
Bob 21 True yes
code snippet:-
fo =open("headerValue.txt", "r")
data = fo.readlines()
for line in data:
if "Age" in line:
if int(Age) > 18:
Eligibility = "True"
Adult = "yes"
I am kinda stuck here since I am new to python. Any help how to update the text file and add headers with its values?Thanks