python飞机订票系统

基于python开发的小课设(飞机订票系统)
代码大概六七百行
包括录入显示查询删除修改显示清空订票退票我的排序等11个功能
设计的时候采取控制台控制,文件存储,未使用数据库,GUI

需预先建立对应的文本文档,否则无法运行

有用就点赞关注一下吧

import random
class Car():
    endName = ""
    hNumber = ""
    fNumber = ""
    p = ""
    Time_ = ""
    AllHave = 0
    Have = 0
    NotHave = 0
    pMoney = 0
    def __init__(self):
        pass


checkP = 0 # 设置输入检查监视哨
flag2 = 0
temp_0 = {}
temp_1 = {}
temp_2 = {}
temp_3 = {}
temp_4 = {}
temp_5 = {}
temp_6 = {}
temp_7 = {}
temp_8 = {}
def searchSystem():
    flag = len(open("carInf.txt", "r",encoding="utf-8").readlines())
    print("欢迎使用查询系统")
    print("1->目的地查询/2->车次查询")
    choice_search = int(input())
    if choice_search == 1 :
        print("请输入目的地")
        cNumber = input()
        with open("carInf.txt", "r",encoding="utf-8") as fp:
            fp.readline()
            for i in range(1, flag):
                temp_4[i] = str(fp.readline())
                stc = temp_4[i].split(",")
                if cNumber == stc[0]:
                    print("找到了要查询的目的地")
                    index = i
                    break
        if i == flag - 1 and cNumber != stc[0]:
            print("没有查询到要查询的数据,查询失败")

        else:
            with open("carInf.txt", "r",encoding="utf-8") as fp:
                for i in range(0, flag):
                    temp_5[i] = str(fp.readline())
            sh = str(temp_5[index]).split(",")
            print("目的地:{0},车牌号:{1},车次号:{2},已订票乘客姓名:{3},行驶时间:{4}".format(sh[0], sh[1], sh[2], sh[3], sh[4], sh[5]))
            print("查询完毕")
    else:
        print("请输入车次")
        cNumber = input()
        i = 0
        with open("carInf.txt", "r",encoding="utf-8") as fp:
            fp.readline()
            for i in range(1, flag):
                temp_4[i] = str(fp.readline())
                stc = temp_4[i].split(",")
                if cNumber == stc[2]:
                    print("找到了要查询的目的地")
                    index = i
                    break
        if i == flag - 1 and cNumber != stc[2]:
            print("没有查询到要查询的数据,查询失败")

        else:
            with open("car3.txt","r",encoding="utf-8") as fp:
                s = fp.readline()
            with open("carInf.txt", "r",encoding="utf-8") as fp:
                for i in range(0, flag):
                    temp_5[i] = str(fp.readline())
            sh = str(temp_5[index]).split(",")
            print("目的地:{0},车牌号:{1},车次号:{2},已订票乘客姓名:{3},行驶时间:{4},乘客姓名:张三,总{5},我的已定:{6},总余票{7}".format(sh[0], sh[1], sh[2], sh[3], sh[4], sh[5],s,sh[8]))
            print("查询完毕")

#删除系统
def deleteAll():
    fp = open("carInf.txt","w",encoding="UTF-8").close()
    fp = open("car_2.txt", "w",encoding="UTF-8").close()
    fp = open("xx.txt", "w",encoding="UTF-8").close()
    print("清除全部信息完毕")


# 录入系统------

def inPut():
    flag = 0
    print("进入录入系统")
    with open("carInf.txt", "r+",encoding="utf-8") as fp:
        fp.seek(0)
        if not fp.read():
            fp.write("按照终点站名,车牌号,车次号,已订票乘客姓名,时间,成员定额,已定票,票价,余票量展示")
    while True:
        print("请输入终点站名")
        while True:
            endName = input() # 终点站名
            count = 0
            for ch in endName:
                count = count + 1
            if count < 0:
                print("终点站名字小于0个字,请重新输入")
            else:
                with open("carInf.txt", "a+",encoding="utf-8") as fp:
                    fp.write("\n")
                    fp.write(endName)
                    fp.writelines(",")
                break
        print("请输入车牌号")
        hNumber = input()
        with open("carInf.txt", "a+",encoding="utf-8") as fp:
            fp.writelines(hNumber)
            fp.writelines(",")
        print("请输入车次号(数字)")
        fNumber = input()
        with open("carInf.txt", "a+",encoding="utf-8") as fp:
            fp.writelines(fNumber)
            fp.writelines(",")
        print("请输入已订票乘客姓名")
        fDay = input()
        with open("carInf.txt", "a+",encoding="utf-8") as fp:
            fp.writelines(fDay)
            fp.writelines(",")
        with open("xx.txt", "a",encoding="utf-8") as fp:
            fp.writelines(fDay)
            fp.writelines(",")
        print("请输入汽车的行驶时间")
        fTime = input()
        with open("carInf.txt", "a+",encoding="utf-8") as fp:
            fp.writelines(fTime)
            fp.writelines(",")
        print("请输入汽车的成员定额")
        while True:
            fMax = int(input())
            if fMax < 0:
                print("成员定额小于0,录入无效,请重新录入")
            else:
                with open("carInf.txt", "a+",encoding="utf-8") as fp:
                    fp.writelines(str(fMax))
                    fp.writelines(",")
                break
        print("请输入汽车的已定票额")
        while True:
            dNumber = int(input())
            if dNumber > fMax:
                print("订票额已经超过了成员载量,不合理请重新输入")
            else:
                with open("carInf.txt", "a+",encoding="utf-8") as fp:
                    fp.writelines(str(dNumber))
                    fp.writelines(",")
                break
        print("请输入汽车的票价")
        while True:
            pMoney = int(input())
            if pMoney < 0:
                print("价格小于0,录入无效,请重新录入")
            else:
                with open("carInf.txt", "a+",encoding="utf-8") as fp:
                    fp.writelines(str(pMoney))
                    fp.writelines(",")
                break
        yNumber = fMax - dNumber
        with open("carInf.txt","a+",encoding="utf-8") as fp:
            fp.write(str(yNumber))
        print("订票人数为{}".format(dNumber))
        print("请继续输入{}人的名字".format(dNumber))
        for im in range(0,dNumber):
            it = input("姓名:")
            with open("xx.txt","a",encoding="UTF-8") as fp:
                fp.write(it)
                fp.write(",")
        print("该车牌信息录入完毕,是否继续录入下一个车牌?")
        flag = flag + 1
        # clearBlankLine()

        c = input("'y/Y'->yes\t'n/N'->no")
        if c == 'y' or c == 'Y':
            continue
        else:
            print("成功退出录入系统")
            break

# 显示系统

def showSystem():
    print("欢迎使用显示系统")
    with open("carInf.txt", "r",encoding="utf-8") as fp:
        for it in fp:
            print(it, end="")
        print()
        print("订票的人: ")
        # -*- coding:utf-8 -*-
        with open("xx.txt","r",encoding="utf-8") as fp:
            Name_R = fp.readline()
        Name_R_list = Name_R.split(",")
        with open("carInf.txt","r",encoding="utf-8") as fp:
            fp.readline()
            res = fp.readlines()
        sum = 0
        for it in res:
            Nums = 0
            res_N = it.split(",")
            Nums = int(res_N[6])
            sum += Nums
        # print(Name_R_list)
        for it in range(0,sum):
            # im = random.randint(0, len(Name_R_list)-1)
            print(Name_R_list[it])

# 删除系统------输入待删除的 ,然后读取后台文件,一行一行的读,因为向后台录入的时候, 是第2个元素,所以分割逗号之后第二个元素就是 ,遍历 ,找到结果,执行删除,
# 所谓删除就是数组迁移,删除第i个元素,就是i后面的元素前移,然后顶掉i

def delSystem():
    flag = len(open("carInf.txt", "r").readlines())
    print("欢迎使用删除系统")
    print("请输入待删除的汽车的车次号")
    delNumber = int(input())

    with open("carInf.txt", "r",encoding="utf-8") as fp:
        fp.readline()
        for i in range(1, flag):
            temp_0[i] = str(fp.readline())
            stc = temp_0[i].split(",")
            if delNumber == int(stc[2]):
                print("找到了要删除的数据")
                index = i
                break
    if i == flag - 1 and delNumber != int(stc[2]):
        print("没有查询到要删除的数据,删除失败")

    else:
        with open("carInf.txt", "r",encoding="utf-8") as fp:
            for i in range(0, flag):
                temp_1[i] = str(fp.readline())
        for j in range(index, flag - 1):
            temp_1[j] = temp_1[j + 1]
        with open("carInf.txt", "w",encoding="utf-8") as fp:
            for i in range(0, flag - 1):
                fp.write(temp_1[i])
        print("删除完成")




# 修改系统------输入待修改的 ,然后读取后台文件,一行一行的读,因为向后台录入的时候, 是第2个元素,所以分割逗号之后第二个元素就是 ,遍历 ,找到结果,重新录入修改位置的结果
def change():
    flag = len(open("carInf.txt", "r").readlines())
    print("欢迎使用修改系统")
    print("请输入待修改的汽车的车次号")
    while True:
        changeNumber = input()
        if changeNumber == '' :
            print("输入的车次号为空,录入无效,请重新输入")
        else:
            break
    with open("carInf.txt", "r",encoding="utf-8") as fp:
        fp.readline()
        for i in range(1, flag):
            temp_2[i] = str(fp.readline())
            stc = temp_2[i].split(",")
            if changeNumber == stc[2]:
                print("找到了要修改的数据")
                index = i
                break
    if i == flag - 1 and changeNumber != stc[2]:
        print("没有查询到要修改的数据,修改失败")

    else:
        with open("carInf.txt", "r",encoding="utf-8") as fp:
            for i in range(0, flag):
                temp_3[i] = str(fp.readline())

        print("请输入终点站名")
        while True:
            endName = input()  # 终点站名
            count = 0
            for ch in endName:
                count = count + 1
            if count < 0:
                print("终点站名字小于0个字,请重新输入")
            else:
                break
        print("请输入车牌号")
        hNumber = input()
        print("请输入车次号")
        fNumber = input()
        print("请输入汽车的行驶日期")
        fDay = input()
        print("请输入已订票乘客姓名")
        fTime = input()
        print("请输入汽车的成员定额")
        while True:
            fMax = int(input())
            if fMax < 0:
                print("成员定额小于0,录入无效,请重新录入")
            else:
                break
        print("请输入汽车的已定票额")
        while True:
            dNumber = int(input())
            if dNumber > fMax:
                print("订票额已经超过了成员载量,不合理请重新输入")
            else:
                break
        print("请输入汽车的票价")
        while True:
            pMoney = int(input())
            if pMoney < 0:
                print("价格小于0,录入无效,请重新录入")
            else:
                break
        yNumber = fMax - dNumber

        temp_3[index] = str(endName) + ',' + str(hNumber) + ',' + str(fNumber) + ',' + str(fDay) + ',' + str(
            fTime) + ',' + str(fMax)  + ',' + str(dNumber)  + ',' + str(pMoney)  + ',' + str(yNumber) + '\n'

        with open("carInf.txt", "w",encoding="utf-8") as fp:
            for i in range(0, flag):
                fp.write(temp_3[i])
        print("修改完成")
        # clearBlankLine()


def preP():
    # clearBlankLine()
    flag = len(open("carInf.txt", "r",encoding="UTF-8").readlines())
    print("欢迎使用订票系统")
    print("请输入车次号")
    userP = input()
    Mars = "xx"
    with open("carInf.txt", "r",encoding="utf-8") as fp:
        fp.readline()
        i = 0
        # stk = {}
        for i in range(1, flag):
            temp_6[i] = str(fp.readline())
            stk = temp_6[i].split(",")
            if userP == stk[2]:
                index = i
                print("找到了")
                print("请输入您的姓名确认")
                Mars = input()
                break
    if i == flag - 1 and userP != stk[2] or Mars !="张三":
        print("订票失败")

    else:
        with open("carInf.txt", "r",encoding="utf-8") as fp:
            for i in range(0, flag):
                temp_6[i] = str(fp.readline())
        shl = str(temp_6[index]).split(",")
        print("车牌号{}的成员定额是{},已定{},余{},票价:{}".format(shl[1],shl[5],shl[6],shl[8],shl[7]))
        while True:
            print("请输入订票额")
            userE = int(input())
            if userE <= 0:
                print("订票额小于等于0,输入不合法,请重新输入")
            else:
                break
        if userE > int(shl[8]):
            print("订的票数超过了余票,订票失败,已返回主菜单")
        else:
            temp = int(shl[8])
            temp -= userE
            shl[8] = str(temp)
            temp = int(shl[6])
            temp += userE
            shl[6] = str(temp)
            print("订票成功,正在更新数据......")
            global checkP
            checkP += userE
            temp_6[index] = str(shl[0])+','+str(shl[1])  + ',' + str(shl[2]) + ',' + str(shl[3]) + ',' + str(shl[4]) + ',' + str(
                shl[5]) + ',' + str(shl[6]) + ',' + str(shl[7]) + ',' + str(shl[8])  + '\n'

            with open("carInf.txt", "w",encoding="utf-8") as fp:
                for i in range(0, flag):
                    fp.write(temp_6[i])

            with open("car_2.txt","w",encoding="utf-8") as fp:
                fp.write(temp_6[index])

            with open("car3.txt","w",encoding="utf-8") as fp:
                fp.write(str(userE))
            print("successful~~~~~~~")





def main_of_Information():
    print("我的信息:")

    print("当前已订车牌如下:")
    flag2 = len(open("car_2.txt", "r",encoding="UTF-8").readlines())
    if flag2 == 0:
        print("当前还没有订单,请先订票再来查看")
    else:
        print("个人信息如下:")
        
        with open("car3.txt","r",encoding="utf-8") as fp:
            shX = fp.readlines()
        with open("car_2.txt",encoding="utf-8") as fp:
            for i in range(0, flag2):
                temp_7[i] = str(fp.readline())
                sh = str(temp_7[i]).split(",")
                print("目的地:{0},车牌号:{1},车次号:{2},已订票乘客姓名:{3},行驶时间:{4},已定:{5}".format(sh[0], sh[1], sh[2], sh[3], sh[4],shX))
                print("打印完毕")


def offP():
    # clearBlankLine()
    flag = len(open("car_2.txt", "r",encoding="UTF-8").readlines())
    print("欢迎使用退票系统")
    print("请输入车次号")
    userP = input()
    Mars = "张三"
    i = 0
    index = 0
    with open("car_2.txt", "r",encoding="utf-8") as fp:

        for i in range(0, flag):
            temp_6[i] = str(fp.readline())
            stk = temp_6[i].split(",")
            if userP == stk[2]:
                index = i
                print("找到了")
                print("请输入您的姓名来确认")
                Mars= input()
                break

    if i == flag - 1 and userP != stk[2] or Mars != "张三":
        print("退票失败")
    else:
        with open("car3.txt","r",encoding="utf-8") as fp:
            shX = fp.readlines()
        shl = str(temp_6[index]).split(",")
        print("车牌号{}的成员定额是{},已定{},余{},票价:{},我的订票:{}".format(shl[1], shl[5], shl[6], shl[8], shl[7],shX))
        while True:
            print("请输入退票的数目")
            userE = int(input())
            if userE <= 0:
                print("退票额小于等于0,输入不合法,请重新输入")
            else:
                break
        if userE > checkP:
            print("退的票数超过了订的票,退票失败,已返回主菜单")
        else:
            temp = int(shl[6])
            temp -= userE
            shl[6] = str(temp)
            temp = int(shl[8])
            temp += userE
            shl[8] = str(temp)
            print("退票成功,正在更新数据......")
            temp_6[index] = str(shl[0]) + ',' + str(shl[2]) + ',' + str(shl[3]) + ',' + str(shl[4]) + ',' + str(
                shl[5]) + ',' + str(shl[6]) + ',' + str(shl[7]) + ',' + str(shl[8]) + '\n'
            print("提示"+temp_6[index])
            with open("car_2.txt", "w",encoding="utf-8") as fp:
                for i in range(0, flag):
                    # print("--------")
                    # print(temp_6[i])
                    fp.write(temp_6[i])
            # 在更新一下主
            index2 = 0
            with open("car3.txt","r",encoding="utf-8") as f:
                q = f.readlines()
            Have = int(q[0])
            flag2 = len(open("carInf.txt", "r").readlines())
            with open("car3.txt","w",encoding="utf-8") as fp:
                fp.write(str(Have-userE))
            with open("carInf.txt","r",encoding="utf-8") as fp:
                fp.readline()
                for it in range(1,flag2):
                    temp_8[i] = fp.readline()
                    sl = str(temp_8[i]).split(",")
                    if sl[1] == userP:
                        index2 = i
                temp_8[index2] = str(shl[0])+','+str(shl[1]) + ',' + str(shl[2]) + ',' + str(shl[3]) + ',' + str(shl[4]) + ',' + str(
                    shl[5]) + ',' + str(shl[6]) + ',' + str(shl[7]) + ',' + str(shl[8]) + '\n'
            with open("carInf.txt","w",encoding="utf-8") as fp :
                fp.write("按照终点站名,车牌号,车次号,已订票乘客姓名,时间,成员定额,已定票,票价,余票量展示\n")
                for it in range(1, flag2):
                    fp.write(temp_8[i])

            print("successful~~~~~~~")


def orderedFun():#排序
    print("欢迎使用排序功能")
    with open("carInf.txt","r",encoding="utf-8") as fp:
        res = fp.readlines()
    app = list()
    endApp = list()
    endApp2 = list()
    for i in res:
        res_1 = i.replace("\n","")
        res_1 = res_1.replace("按照终点站名,车牌号,车次号,已订票乘客姓名,时间,成员定额,已定票,票价,余票量展示","")
        if res_1 != "":
            res_2 = res_1.split(",")

            # print(res_2)
            app.append(res_2[8])
            endApp.append(res_2[8])
            endApp2.append(res_2[2])

    T = 0
    j = 0
    a = {}
    for it in app:
        Temp = int(it)
        a[j] = Temp
        j += 1
    for m in range(0,j-1):
        for n in range(0,j-m-1):
            if a[n] < a[n+1]:
                T = a[n]
                a[n] = a[n+1]
                a[n+1] = T
    print("排序之后车次是:{}".format(endApp2))
    print("具体:")
    for k in range(0,j):
        if k != j-1:
            print("{}and".format(a[k]),end="")
        else:
            print(a[k])



    # 主函数使用无限循环,保证程序不会因执行完一个模块之后就退出,除非输入6退出程序,不然执行完录入系统,还可以重新选择其他功能,不会退出
if __name__ == '__main__':
    while True:
        print("   ==-----汽车订票系统-----==")
        print("|| 1---------录入信息---------       ||")
        print("|| 2---------删除信息---------       ||")
        print("|| 3---------修改信息---------       ||")
        print("|| 4---------显示全部---------       ||")
        print("|| 5---------查询信息---------       ||")
        print("|| 6---------退出程序---------       ||")
        print("|| 7---------清空全部信息-----       ||")
        print("|| 8---------订票系统--------        ||")
        print("|| 9---------退票系统--------        ||")
        print("|| 10---------我的--------           ||")
        print("|| 11---------排序--------           ||")
        print("请输入您的选择")
        choice = int(input())
        if choice == 1:
            inPut()
        elif choice == 2:
            delSystem()
        elif choice == 3:
            change()

        elif choice == 4:
            showSystem()
        elif choice == 5:
            searchSystem()
        elif choice == 6:
            print("退出成功")
            break
        elif choice == 7:
            deleteAll()
        elif choice == 8:
            # clearBlankLine()
            preP()
        elif choice == 9:
            offP()
        elif choice == 10:
            main_of_Information()
        elif choice == 11:
            orderedFun()
        else:
            print("输入格式错误,请重新输入")

  • 9
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五弦奏南风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值