def file_read ():
dictionary = {}
state = ""
capital = ""
flag = 0
with open("state_capitals.txt","r") as f:
for line in f:
if flag == 0:
state = line.rstrip('\n')
flag = 1
elif flag == 1:
capital = line.rstrip('\n')
flag = 0
dictionary[state] = capital
print(dictionary)
How would I use a while loop to make the dictionary instead of the for loop. Code works perfectly fine but professor insists I use a while loop.