So I want to run a program that will read in a file line by line, and will then print out either Valid or Invalid based on what each line contains.
For this example, I am saying that the input file line can contain ABCabc or a space. If the line only contains these things, the word Valid should be printed. If it is just white space, or contains any other characters or letters, it should print out “Invalid”.
This is what I have come up with:
I can’t seem to get it to ever print out “Valid”
Can you tell why? Thanks!
input = sys.argv[1]
input = open(input,"r")
correctInput = ‘ABCabc ‘
line1 = input.readline()
while line1 != "":
if all(char in correctInput for char in line1):
print “Valid”
line2 = input.readline()
else:
print “Invalid”
line2 = input.readline()
line1 = line2