Ask Question

Write a program that queries information from three files. The first file (data1. txt) contains the names and telephone numbers of a group of people. The second file (data2. txt) contains the names and Social Security numbers of a group of people. The third file (data3. txt) contains the Social Security numbers and annual incomes of a group of people. The groups of people should overlap but need not be completely identical. Your program should ask the use for a telephone number and then print the name, Social Security number, and annual income, if it can determine that information.

+3
Answers (1)
  1. 30 December, 08:04
    0
    file1=[ ]

    file2=[ ]

    file3=[ ]

    f1=open ('data1. txt','r')

    for line in f1:

    line=line. strip (). split (', ')

    file1. append ((line[0], line[1]))

    f1. close ()

    f2=open ('data2. txt','r')

    for line in f2:

    line=line. strip (). split (', ')

    file2. append ((line[0], line[1]))

    f2. close ()

    f3=open ('data3. txt','r')

    for line in f3:

    line=line. strip (). split (', ')

    file3. append ((line[0], line[1]))

    f3. close ()

    l=[ ]

    for x in file2:

    for y in file3:

    if x[1] in y:

    l. append ((x[0], y))

    final_file=[]

    for x in file1:

    for y in l:

    if x[0] in y:

    final_file. append ((x[1], y[0],*y[1]))

    #This is where the program will ask the user for their telephone number

    tel_num=input ('Enter the telephone number: ')

    temp=0

    for data in final_file:

    if data[0]==tel_num:

    temp=1

    print ('Telephone number: ', tel_num)

    print ('Name: ', data[1])

    print ('Social Security number: ', data[2])

    print ('Annual income: ', data[3])

    if temp==0:

    print ('No data available for this telephone number.')
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that queries information from three files. The first file (data1. txt) contains the names and telephone numbers of a group ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers