Программа продажи билетов на паром Python - PullRequest
0 голосов
/ 24 июня 2018

Мне необходимо составить программу по бронированию билетов, я уже составил список мест для сидения, который выглядит примерно так:

def SC1000():
     print(" ")
     print(" ")
     print("PURCHASING MODULE")
     print ("Your booking reference number is : ", bookingref)
     print("B - to purchase ticket for Business class")
     print("E - to purchase ticket for Economy class")
     print("M - to return to Main Menu")
     bore=input("Enter your choice : ")
     if (bore=="B"):
          seatingchoice = [[" ", "A", "B", "C", "D", "E"],
                           ["1" , "0" , "0" , "0" , "0" , "0"],
                           ["2" , "0" , "0" , "0" , "0" , "0"]]
          print("Seating Arrangement")
          print("Business Class")


          format_string="{:>4} {:>4} {:>4} {:>4} {:>4} {:>4}"

          headers = seatingchoice [0]
          header_row = format_string.format(*headers)
          print(header_row)
          print("-" * len(header_row))


          for language in seatingchoice [1:3]:
              print(format_string.format(*language))


          sc=input("Enter your choice (eg:A3/a3): ")
          if sc in open('sc1000.txt').read():
              print("This seat has been taken, kindly choose another seat")
              SC1000()

          else:
             customersdata=[]
             name =input("Please enter your full name : ")
             cfile = open("sc1000.txt","a")
             cfile.write("\n")
             cfile.write(str(customersdata))
             cfile.close()

          #for line in cfile:
             if (sc=="A1") in open("sc1000.txt","r")():
                  seatingchoice[2][2]= 1
             elif (sc=="A2") in open("sc1000.txt","r")():
                  seatingchoice[3][2]= 1
             elif (sc=="B1") in open("sc1000.txt","r")():
                  seatingchoice[2][3]= 1
             elif (sc=="B2") in open("sc1000.txt","r")():
                  seatingchoice[3][3]= 1
             elif (sc=="C1") in open("sc1000.txt","r")():
                  seatingchoice[2][4]= 1




             customersdata.append(bookingref)
             customersdata.append(name)
             customersdata.append(sc)

             print("Boarding Ticket")
             print("____________________________________")
             print(" ")
             print("            Date:",time.strftime("%d/%m/%Y"))
             print("             Time:",time.strftime("%I:%M:%S"))
             print(" Name          : ",name)
             print(" Ferry ID      : Ferry 1")
             print(" Boarding Time : 9.50am")
             print(" Departure     : Penang to Langkawi")
             print(" Seating Class : Business Class")
             print(" Seat Number   : ",sc)
             print(" Zone          : A")
             print(" Gate          : B1")
             print("_____________________________________")
             print(" ")
             print("Kindly print out the boarding pass as it will be needed at the gate.")
             gmm=input("When done printing, press 'D' to go back to the Main Menu. ")
             if (gmm=="D"):
                  mainmenu()

, и это работает, но мне нужнотакже сохраняйте данные, когда пользовательские ключи, в каких местах они хотят, прямо сейчас не сохраняют данные клиентов в текстовый файл, и я уверен, что с моими кодами что-то не так, но я не могу понять, что именно.

ТАКЖЕ , если кто-нибудь захочет поделиться со мной о том, как изменить 0 на 1, когда пользователь выбирает А1, например, это было бы действительно здорово!

Спасибо за вашу помощь

Ответы [ 2 ]

0 голосов
/ 26 июня 2018

@ Ответ Джона Гордона правильный; вы в настоящее время пишете пустой список в файл, а затем добавляете элементы в список. Чтобы это исправить, добавьте элементы в список, , затем запишите его в файл. Вот фрагмент кода с фиксированным кодом:

      else:
         customersdata=[]
         name =input("Please enter your full name : ")

         if (sc=="A1") in open("sc1000.txt","r")():
              seatingchoice[2][2]= 1
         elif (sc=="A2") in open("sc1000.txt","r")():
              seatingchoice[3][2]= 1
         elif (sc=="B1") in open("sc1000.txt","r")():
              seatingchoice[2][3]= 1
         elif (sc=="B2") in open("sc1000.txt","r")():
              seatingchoice[3][3]= 1
         elif (sc=="C1") in open("sc1000.txt","r")():
              seatingchoice[2][4]= 1
         customersdata.append(bookingref)
         customersdata.append(name)
         customersdata.append(sc)
         cfile = open("sc1000.txt","a")
         cfile.write("\n")
         cfile.write(str(customersdata))
         cfile.close()
0 голосов
/ 24 июня 2018

прямо сейчас это не сохранение данных клиентов в текстовый файл

Это потому, что вы пишете пустой customersdata список:

 customersdata=[]
 name =input("Please enter your full name : ")
 cfile = open("sc1000.txt","a")
 cfile.write("\n")
 cfile.write(str(customersdata))
 cfile.close()
...