Conservation of structured data



  • Write a program that, through the menu, enabled the creation of a record, adding, editing, removing, etc. The programme further provides for the manipulation of a list of the nature of the relevant subject area (e.g., to separate the list on a given criterion, to search, etc.).

    Where's the mistake in the function sorting()?

    function.py

    import pickle
    

    def file_open():
    inf = open("pickle.pkl", "rb")
    air_list = pickle.load(inf)
    inf.close()
    return air_list

    def file_close(air_list):
    fout = len(air_list)
    out = open("pickle.pkl", "wb")
    pickle.dump(air_list, out, fout)
    out.close

    def addAirplane(air_list):
    list1 = [[],[],[],[],[],[],[]]
    list1[0] = input("\n Enter ID: ")
    list1[1] = input(" Enter destination: ")
    list1[2] = input(" Enter flight number: ")
    list1[3] = input(" Enter aircraft type: ")
    list1[4] = input(" Enter departure time: ")
    list1[5] = input(" Enter day of week: ")
    air_list.append(list1)

    def delete(air_list):
    count = 0
    id = int(input(" Enter ID: "))
    for i in range(len(air_list)):
    if(id == int(air_list[i][0])):
    count = 1
    air_list.remove(air_list[i])
    break
    if (not count):
    print("There are not record with this ID.")

    def show(air_list):
    print("\t Information \n")
    for i in range(len(air_list)):
    print(" ID: ", air_list[i][0])
    print(" Destination: ",air_list[i][1])
    print(" Flight number: ",air_list[i][2])
    print(" Aircraft type: ",air_list[i][3])
    print(" Departure time: ",air_list[i][4])
    print(" Day fo week: ",air_list[i][5])
    print("\n")
    return

    def search(air_list):
    count = 0
    id = int(input(" Enter ID: "))
    for i in range(len(air_list)):
    if(id == int(air_list[i][0])):
    count += 1
    print("\n ID: ", air_list[i][0])
    print(" Destination: ",air_list[i][1])
    print(" Flight number: ",air_list[i][2])
    print(" Aircraft type: ",air_list[i][3])
    print(" Departure time: ",air_list[i][4])
    print(" Day fo week: ",air_list[i][5])
    print("\n")
    if (not count):
    print("There are not record with this ID.")

    def sorting(air_list, x):
    air_list1 = []
    m = 0
    for i in air_list:
    sotr_el = []
    sort_el.append(m)
    sort_el.append(int(i[x]))
    air_list1.append(sort_el)
    m += 1
    air_list1.sort(key=lambda air_list1:air_list1[1])
    for i in range(len(air_list1)):
    print(" ID: ",air_list1[i][0])
    print(" Destination: ",air_list1[i][0][0])
    print(" Flight number: ",air_list1[i][0][1])
    print(" Aircraft type: ",air_list[i][0][2])
    print(" Departure time: ",air_list1[i][0][3])
    print(" Day fo week: ",air_list1[i][0][4])
    print("\n")
    return

    def menu():
    n = int(input("""\n\tMenu: \n
    1. Show all the record
    2. Add record
    3. Delete record
    4. Search records
    5. Sort of records
    6. Exit

    Enter your choice: """))

    return n

    main.py

    import pickle
    from function import *

    air_list = []

    while True:
    air_list = file_open()
    n = menu()

    if (n == 1):
        show(air_list)
    if (n == 2):
        addAirplane(air_list)
    if (n == 3):
        delete(air_list)
    if (n == 4):
        search(air_list)
    if (n == 5):
        x = int(input(("\n 0 - Sorting by ID,\n 1 - Sorting by fligh number)\n")))
        sorting(air_list, x)
    if (n == 6):
        break
    file_close(air_list)
    

    input(" Press enter for exit...")



  • Stroke inf = ("pickle.pkl", "rb") - not the file, but the cortege is missed. open♪ Right, pickle Makes an exception to this.

    Type- int(input(" ID: ")) free of emergency exit try-except call for an emergency completion of the entire programme if the user has not introduced a whole number. Like missing files.

    In the line list_air.append(sort) variable sort Not defined.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2