欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python編寫車票訂購(gòu)系統(tǒng)?Python實(shí)現(xiàn)快遞收費(fèi)系統(tǒng)

 更新時(shí)間:2022年08月14日 13:58:12   作者:M大王派我來巡山  
這篇文章主要為大家詳細(xì)介紹了Python編寫車票訂購(gòu)系統(tǒng),Python實(shí)現(xiàn)快遞收費(fèi)系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Python編寫車票訂購(gòu)系統(tǒng),Python實(shí)現(xiàn)快遞收費(fèi)系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

要求:

1.上網(wǎng)查詢鄭州到北京,西安,石家莊,濟(jì)南,太原,武漢的距離及票價(jià),用數(shù)據(jù)庫(kù)保存車次信息
2.要求輸入目的地,能夠查詢到里程和票價(jià)
3.用數(shù)據(jù)庫(kù)存儲(chǔ)每一次售票記錄,包括售票流水號(hào),起點(diǎn)站,終點(diǎn)站,里程,金額等數(shù)據(jù),并統(tǒng)計(jì)所有存儲(chǔ)記錄的總售票金額及各站的旅客流量(進(jìn)站流量+出站流量)
4.能夠打印票據(jù)信息,包括訂票人信息,票價(jià),票據(jù)號(hào),車次等信息

import sqlite3
import os
import time
def createDB():
? ?"""
? ? ? 創(chuàng)建并初始化數(shù)據(jù)庫(kù)
? ?"""
? ?# 原始數(shù)據(jù)
? ?info = [("G1564", "鄭州", "北京", "309", "693"), ("G802", "鄭州", "北京", "315", "693"), ("G564", "鄭州", "北京", "326.5", "693"),
? ? ? ? ?("G2025", "鄭州", "西安", "239", "479.3"), ("D311", "鄭州", "西安", "159", "479.3"), ("G857", "鄭州", "西安", "229", "479.3"),
? ? ? ? ?("G1286", "鄭州", "石家莊", "189.5", "417.9"), ("G2070", "鄭州", "石家莊", "196", "417.9"), ("G430", "鄭州", "石家莊", "208", "417.9"),
? ? ? ? ?("G2074", "鄭州", "濟(jì)南", "303", "446"), ("G258", "鄭州", "濟(jì)南", "312.5", "446"), ("G1844", "鄭州", "濟(jì)南", "298.5", "446"),
? ? ? ? ?("D290", "鄭州", "太原", "189", "432.7"), ("D3348", "鄭州", "太原", "153", "432.7"), ("D2782", "鄭州", "太原", "171", "432.7"),
? ? ? ? ?("G1991", "鄭州", "武漢", "244", "509.8"), ("G3203", "鄭州", "武漢", "314", "509.8"), ("G8171", "鄭州", "武漢", "248", "509.8")]
? ?con = sqlite3.connect("DB.db")#連接到數(shù)據(jù)庫(kù)
? ?cur = con.cursor() ? ? # 創(chuàng)建游標(biāo)對(duì)象
? ?# 創(chuàng)建字段,num是車次,station是始發(fā)站,destination是目的地,price票價(jià),distance是距離
? ?cur.execute("create table test(num primary key, station, destination, price, distance)")
? ?for i in info:
? ? ? cur.execute("insert into test values(?,?,?,?,?)", i)
? ?con.commit()
? ?cur.close()
? ?con.close()
def CreateSaleDB():
? ?"""
? ?創(chuàng)建銷售數(shù)據(jù)庫(kù)
? ?"""
? ?con = sqlite3.connect("sale.db")
? ?cur = con.cursor()
? ?# 字段依次為流水號(hào),起點(diǎn)站,終點(diǎn)站,金額,里程
? ?cur.execute("create table sheet(num,station,destination,price,distance)")
? ?con.commit()
? ?cur.close()
? ?con.close()

# 根據(jù)目的地查詢車票信息
def Query(dest):
? ?con = sqlite3.connect("DB.db")
? ?cur = con.cursor()
? ?item = cur.execute("select * from test where destination=?", (dest,))
? ?print("--------------------------查詢到的信息--------------------------")
? ?for i in item.fetchall():
? ? ? print("車次:%s ? ? ?%s==>%s ? ? ? 票價(jià):%s元 ? ?距離:%skm" % (i[0], i[1], i[2], i[3], i[4]))
? ?print("--------------------------------------------------------------")
? ?cur.close()
? ?con.close()
def SaveSaleRecord(num, SerialNumber):
? ?con = sqlite3.connect("DB.db")
? ?cur = con.cursor()
? ?item = cur.execute("select * from test where num=?", (num,))
? ?data = []
? ?data.append(SerialNumber)
? ?for i in item.fetchall():
? ? ? data.append(i[1])
? ? ? data.append(i[2])
? ? ? data.append(i[3])
? ? ? data.append(i[4])
? ?cur.close()
? ?con.close()

? ?data = tuple(data)
? ?con = sqlite3.connect("sale.db")
? ?cur = con.cursor()
? ?cur.execute("insert into sheet values(?,?,?,?,?)", data)
? ?con.commit()
? ?cur.close()
? ?con.close()
? ?return data

def Statistics():
? ?con = sqlite3.connect("sale.db")
? ?cur = con.cursor()
? ?item = cur.execute("select * from sheet")

? ?total_sale = 0
? ?# 進(jìn)出站客流量統(tǒng)計(jì)列表,進(jìn)站/出站
? ?zhengzhou = [0, 0]
? ?beijing = [0, 0]
? ?xian = [0, 0]
? ?shijiazhuang = [0, 0]
? ?jinan = [0, 0]
? ?taiyuan = [0, 0]
? ?wuhan = [0, 0]
? ?for i in item.fetchall():
? ? ? temp = float(i[3])
? ? ? total_sale = temp + total_sale
? ? ? # 流水號(hào),起點(diǎn)站,終點(diǎn)站,金額,里程

? ? ? # 進(jìn)站統(tǒng)計(jì)
? ? ? if i[1] == '鄭州':
? ? ? ? ?zhengzhou[0] += 1
? ? ? elif i[1] == '北京':
? ? ? ? ?beijing[0] += 1
? ? ? elif i[1] == '西安':
? ? ? ? ?xian[0] += 1
? ? ? elif i[1] == '濟(jì)南':
? ? ? ? ?jinan[0] += 1
? ? ? elif i[1] == '石家莊':
? ? ? ? ?shijiazhuang[0] += 1
? ? ? elif i[1] == '武漢':
? ? ? ? ?wuhan[0] += 1
? ? ? elif i[1] == '太原':
? ? ? ? ?taiyuan[0] += 1

? ? ? # 出站統(tǒng)計(jì)
? ? ? if i[2] == '鄭州':
? ? ? ? ?zhengzhou[1] += 1
? ? ? elif i[2] == '北京':
? ? ? ? ?beijing[1] += 1
? ? ? elif i[2] == '西安':
? ? ? ? ?xian[1] += 1
? ? ? elif i[2] == '濟(jì)南':
? ? ? ? ?jinan[1] += 1
? ? ? elif i[2] == '石家莊':
? ? ? ? ?shijiazhuang[1] += 1
? ? ? elif i[2] == '武漢':
? ? ? ? ?wuhan[1] += 1
? ? ? elif i[2] == '太原':
? ? ? ? ?taiyuan[1] += 1

? ?print("--------進(jìn)出站統(tǒng)計(jì)--------")
? ?print(" ? ? ? 進(jìn)站 ? ? ? 出站")
? ?print("鄭州 ? ? ?%d ? ? ? ? ? %d" % (zhengzhou[0], zhengzhou[1]))
? ?print("北京 ? ? ?%d ? ? ? ? ? %d" % (beijing[0], beijing[1]))
? ?print("石家莊 ?%d ? ? ? ? ? %d" % (shijiazhuang[0], shijiazhuang[1]))
? ?print("西安 ? ? ?%d ? ? ? ? ? %d" % (xian[0], xian[1]))
? ?print("太原 ? ? ?%d ? ? ? ? ? %d" % (taiyuan[0], taiyuan[1]))
? ?print("濟(jì)南 ? ? ?%d ? ? ? ? ? %d" % (jinan[0], jinan[1]))
? ?print("武漢 ? ? ?%d ? ? ? ? ? %d" % (wuhan[0], wuhan[1]))
? ?print("------------------------")
? ?print("總銷售額:%.2f元" % total_sale)
? ?cur.close()
? ?con.close()

def PrintData(data, num):
? ?"""
? ?打印票據(jù)信息
? ?"""
? ?print("--------票據(jù)信息--------")
? ?print("車次:%s" %num)
? ?print("票據(jù)號(hào):%s" %data[0])
? ?print("票價(jià):%s元" %data[3])
? ?print("----------------------")

if __name__ == '__main__':
? ?# 創(chuàng)建數(shù)據(jù)庫(kù)DB.db
? ?if os.path.exists("DB.db"):
? ? ? pass
? ?else:
? ? ? # 創(chuàng)建數(shù)據(jù)庫(kù)并初始化
? ? ? createDB()

? ?# 創(chuàng)建銷售數(shù)據(jù)庫(kù),存儲(chǔ)銷售記錄
? ?if os.path.exists("sale.db"):
? ? ? pass
? ?else:
? ? ? CreateSaleDB()
? ?flag = 1
? ?while(flag):
? ? ? print("********歡迎使用車票訂購(gòu)系統(tǒng)*******")
? ? ? print('請(qǐng)選擇您的進(jìn)一步操作')
? ? ? print('1.查詢車次信息')
? ? ? print('2.售票記錄和票據(jù)信息')
? ? ? print('3.各站旅客流量統(tǒng)計(jì)')
? ? ? print('4.退出系統(tǒng)')
? ? ? a = int(input("請(qǐng)輸入選項(xiàng):"))
? ? ? if a == 1:
? ? ? ? ?dest = input("請(qǐng)輸入目的地:")
? ? ? ? ?Query(dest)
? ? ? ? ?# num, SerialNumber = Query(dest) ?# num是購(gòu)買的車次,SerialNumber是流水號(hào)
? ? ? elif a == 2:
? ? ? ? ?num = input("請(qǐng)輸入要購(gòu)買的車次:")
? ? ? ? ?SerialNumber = time.strftime("%Y%m%d%H%M%S", time.localtime()) ?# 作為流水號(hào)
? ? ? ? ?data = SaveSaleRecord(num, SerialNumber) ?# 保存售票記錄,返回購(gòu)票信息以供打印票據(jù)用
? ? ? ? ?PrintData(data, num) ?# 打印票據(jù)信息
? ? ? elif a == 3:
? ? ? ? ?Statistics() ?# 統(tǒng)計(jì)
? ? ? elif a == 4:
? ? ? ? ?break
? ? ? else:
? ? ? ? ?print('輸入錯(cuò)誤,請(qǐng)重新輸入?。?!')

程序運(yùn)行結(jié)果如圖所示:

還有一個(gè)是快遞收費(fèi)系統(tǒng),要求啥的找不到了,只剩代碼

import sqlite3
#定義區(qū)域快遞費(fèi)
q=[10,10,15,15,15]
x=[3,4,5,6.5,10]
#打開數(shù)據(jù)庫(kù)
def opendb():
? ? #創(chuàng)建全局變量方便其他函數(shù)調(diào)用
? ? global conn
? ? global cur
? ? conn=sqlite3.connect('customer.db')
? ? cur=conn.cursor()
? ? cur.execute('''create table if not exists customers(num,name,distance)''')
? ? #添加數(shù)據(jù)
? ? p0 = [('0', "上海", "同城"), ('1', "江蘇", "臨近兩省"), ('1', "浙江", "臨近兩省"), ('2', "北京", "1500公里(含)以內(nèi)"), ('2', "天津", "1500公里(含)以內(nèi)"), ('2', "河北", "1500公里(含)以內(nèi)")]
? ? p1 = [('2', "河南", "1500公里(含)以內(nèi)"), ('2', "安徽", "1500公里(含)以內(nèi)"), ('2', "陜西", "1500公里(含)以內(nèi)"), ('2', "湖北", "1500公里(含)以內(nèi)"), ('2', "江西", "1500公里(含)以內(nèi)"), ('2', "湖南", "1500公里(含)以內(nèi)")]
? ? p2 = [('2', "福建", "1500公里(含)以內(nèi)"), ('2', "廣東", "1500公里(含)以內(nèi)"), ('2', "山西", "1500公里(含)以內(nèi)"), ('3', "吉林", "1500-2500公里"), ('3', "甘肅", "1500-2500公里"), ('3', "四川", "1500-2500公里")]
? ? p3 = [('3', "重慶", "1500-2500公里"), ('3', "青海", "1500-2500公里"), ('3', "廣西", "1500-2500公里"), ('3', "云南", "1500-2500公里"), ('3', "海南", "1500-2500公里"), ('3', "內(nèi)蒙古", "1500-2500公里")]
? ? p4 = [('3', "黑龍江", "1500-2500公里"), ('3', "貴州", "1500-2500公里"), ('3', "遼寧", "1500-2500公里"), ('4', "新疆", "2500公里以上"), ('4', "西藏", "2500公里以上")]
? ? cur.executemany('''insert into customers values(?,?,?)''',p0)
? ? cur.executemany('''insert into customers values(?,?,?)''',p1)
? ? cur.executemany('''insert into customers values(?,?,?)''',p2)
? ? cur.executemany('''insert into customers values(?,?,?)''',p3)
? ? cur.executemany('''insert into customers values(?,?,?)''',p4)
#輸出分隔線
def interval():
? ? print('**************************************')
#計(jì)算快遞費(fèi)
def Calculation():
? ? num=int(input('請(qǐng)輸入?yún)^(qū)域編碼(0-4):'))
? ? if num<=4:
? ? ? ? weight = float(input('請(qǐng)輸入快遞重量(公斤):'))
? ? ? ? #不足1公斤按1公斤計(jì)算
? ? ? ? if weight!=int(weight):
? ? ? ? ? ? weight=int(weight)+1
? ? ? ? s=q[num]+(weight-1)*x[num]
? ? ? ? print('所需快遞費(fèi)為:%.2f'%s)
? ? ? ? interval()
? ? else:
? ? ? ? print('區(qū)域編號(hào)錯(cuò)誤!請(qǐng)重新輸入!')
? ? ? ? Calculation()
#修改區(qū)域快遞費(fèi)
def modify():
? ? #輸出目前區(qū)域快遞費(fèi)方便修改
? ? print("目前區(qū)域快遞費(fèi)為:")
? ? Inquire2()
? ? num=int(input('請(qǐng)輸入要修改的區(qū)域編碼(0-4):'))
? ? if num<=4:
? ? ? ? q[num]=float(input('請(qǐng)輸入修改后的起重費(fèi):'))
? ? ? ? x[num]=float(input('請(qǐng)輸入修改后的續(xù)重費(fèi):'))
? ? ? ? print('修改成功!')
? ? ? ? #修改完成后輸出修改后的區(qū)域快遞費(fèi)
? ? ? ? print('修改后的地區(qū)快遞費(fèi)為:')
? ? ? ? Inquire2()
? ? ? ? interval()
? ? else:
? ? ? ? print('區(qū)域編號(hào)錯(cuò)誤!請(qǐng)重新輸入!')
? ? ? ? modify()
#查詢地區(qū)編碼
def Inquire1():
? ? global cur
? ? cur.execute('''select * from customers order by num asc''')
? ? print('地區(qū)編碼\t\t地區(qū)名稱\t\t地區(qū)距離')
? ? for i in cur:
? ? ? ? print('%-5s\t\t%-5s\t\t%-5s'%(i[0],i[1],i[2]))
? ? interval()
#查詢地區(qū)快遞費(fèi)
def Inquire2():
? ? print('地區(qū)編碼\t\t起重費(fèi)(元)\t\t續(xù)費(fèi)(元/公斤)')
? ? for i in range(5):
? ? ? ? print(i,"\t\t\t%.2f\t\t\t%.2f"%(q[i],x[i]))
#刪除數(shù)據(jù)
def delete():
? ? a=input('請(qǐng)輸入要?jiǎng)h除的地區(qū)名稱:')
? ? global cur
? ? cur.execute('''select * from customers where name="%s"'''%a)
? ? print('地區(qū)編碼\t\t地區(qū)名稱\t\t地區(qū)距離')
? ? for i in cur:
? ? ? ? print('%-5s\t\t%-5s\t\t%-5s'%(i[0],i[1],i[2]))
? ? print('1.確認(rèn)刪除')
? ? print('2.取消')
? ? b=int(input())
? ? if b==1:
? ? ? ? cur.execute('''delete from customers where name="%s"'''%a)
? ? ? ? print('刪除成功!')
? ? else:
? ? ? ? print('取消刪除!')
#添加數(shù)據(jù)
def add():
? ? global cur
? ? a = input('請(qǐng)輸入要添加的地區(qū)編號(hào):')
? ? b = input('請(qǐng)輸入要添加的地區(qū)名稱:')
? ? c = input('請(qǐng)輸入要添加的地區(qū)距離:')
? ? s=[(a,b,c)]
? ? cur.executemany('''insert into customers values(?,?,?)''',s)
? ? print('添加成功!')
opendb()
print('**********歡迎使用快遞費(fèi)計(jì)算系統(tǒng)**********')
while 1>0:
? ? print('請(qǐng)選擇您的進(jìn)一步操作')
? ? print('1:添加數(shù)據(jù)')
? ? print('2:計(jì)算快遞費(fèi)')
? ? print('3:查詢地區(qū)編碼')
? ? print('4:查詢區(qū)域快遞費(fèi)')
? ? print('5:修改區(qū)域快遞費(fèi)')
? ? print('6:刪除數(shù)據(jù)')
? ? print('7:退出系統(tǒng)')
? ? a=int(input())
? ? if a==1:
? ? ? ? add()
? ? elif a==2:
? ? ? ? Calculation()
? ? elif a==3:
? ? ? ? Inquire1()
? ? elif a==4:
? ? ? ? Inquire2()
? ? ? ? interval()
? ? elif a==5:
? ? ? ? modify()
? ? elif a==6:
? ? ? ? delete()
? ? elif a==7:
? ? ? ? break
? ? else:
? ? ? ? print('輸入錯(cuò)誤!請(qǐng)重新輸入!')
? ? ? ? interval()
conn.commit()
cur.close()
conn.close()

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論