Skip to main content

Read Age From File and check vote eligibility

· One min read
Kaustubh Kulkarni

Que > Write a program to read Name and age of person from file named file.txt' and print if person is eligible for voting or not.

file.txt
Your Name,24
Program.py
def checkAge(name,age):
if (int(age)>18):
print(name+" is eligible for voting")
else:
print(name+" is not eligible for voting")
f=open("file.txt")
content=f.read()
data=content.split(",")
checkAge(data[0],data[1])

Output > Output