您好,登錄后才能下訂單哦!
基于Python如何實(shí)現(xiàn)電影售票系統(tǒng),很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
電影售票系統(tǒng)程序,應(yīng)具備以下幾點(diǎn)功能:
1.用戶認(rèn)證
系統(tǒng)用戶分為用戶、管理員兩個(gè)角色,系統(tǒng)可根據(jù)不同用戶角色權(quán)限進(jìn)入不同界面,所有用戶角色需要通過身份驗(yàn)證才能登錄系統(tǒng)進(jìn)行操作。
2.用戶登錄
主要實(shí)現(xiàn)用戶登錄系統(tǒng)可查看本人會(huì)員信息、購(gòu)買影票、查看訂票、影票退訂、修改信息等功能。
3.管理登錄
主要實(shí)現(xiàn)管理員登錄系統(tǒng)可查看會(huì)員和管理信息、添加會(huì)員、注銷會(huì)員、查看購(gòu)票、影票出售、影票退訂、查看影票余票和售票、增刪管理、增刪影片、修改信息等功能。
數(shù)據(jù)信息行較多,如小伙伴需要可點(diǎn)擊鏈接前往進(jìn)行下載: 博客小程序—電影售票系統(tǒng)數(shù)據(jù)下載
1.管理系統(tǒng)
import json,time,re from managements import management_login from users import users_login from registered import registered from back import back read_movie = open('movie.json', 'r', encoding='utf-8') movie = json.loads(read_movie.read()) read_user = open('user.json', 'r', encoding='utf-8') user = json.loads(read_user.read()) read_management = open('management.json', 'r', encoding='utf-8') management = json.loads(read_management.read()) read_ticket_record = open('ticket_record.json', 'r', encoding='utf-8') ticket_record = json.loads(read_ticket_record.read()) def movie_tickets(): while True: permissions = input('請(qǐng)您選擇用戶操作(1.用戶登錄 2.注冊(cè)用戶 3. 找回密碼 4.退出系統(tǒng)):') if permissions == '1': while True: login = input('請(qǐng)您選擇登錄權(quán)限(1.個(gè)人登錄 2.管理登錄 3.退出登錄):') if login == '1': users_login(user, movie, ticket_record) elif login == '2': management_login(management, user, movie, ticket_record) elif login == '3': break elif permissions == '2': registered(user) elif permissions == '3': back(management, user) elif permissions == '4': break movie_tickets() save = open('movie.json', 'w', encoding='utf-8') json.dump(movie, save, ensure_ascii=False, indent=4) save = open('user.json', 'w', encoding='utf-8') json.dump(user, save, ensure_ascii=False, indent=4) save = open('management.json', 'w', encoding='utf-8') json.dump(management, save, ensure_ascii=False, indent=4) save = open('ticket_record.json', 'w', encoding='utf-8') json.dump(ticket_record, save, ensure_ascii=False, indent=4)
2.管理登錄
import time, re operation = '''********歡迎使用漫漫影院系統(tǒng)********* 1.查看信息 2.添加會(huì)員 3.注銷會(huì)員 4.查看購(gòu)票 5.影票出售 6.影票退訂 7.查看余票 8.增刪管理 9.增刪影片 10.銷售記錄 11.修改信息 12.退出系統(tǒng) *********************************''' def management_login(a, b, c, d): account = input('請(qǐng)您輸入賬號(hào):') password = input('請(qǐng)您輸入密碼:') if account in a: if a[account][0] == password: time.sleep(0.5) print('密碼正確,登錄成功!') while True: print(operation) choose = input('請(qǐng)您選擇操作選項(xiàng):') if choose == '1': while True: query = input('請(qǐng)你選擇查詢選項(xiàng)(1.查詢會(huì)員 2.查詢管理 3.退出查詢):') if query == '1': for i in b: time.sleep(0.5) print('會(huì)員卡號(hào):{}、會(huì)員昵稱:{}、會(huì)員性別:{}、手機(jī)號(hào)碼:{}'.format (i, b[i][1], b[i][2], b[i][3])) elif query =='2': for i in a: time.sleep(0.5) print('管理賬號(hào):{}、管理昵稱:{}、管理性別:{}、手機(jī)號(hào)碼:{}'.format (i, a[i][1], a[i][2], a[i][3])) elif query == '3': break elif choose == '2': while True: add = input('是否需要添加會(huì)員(1.需要 2.退出):') if add == '2': break else: name = input('請(qǐng)您輸入會(huì)員昵稱:') gender = input('請(qǐng)您輸入會(huì)員性別:') phone = input('請(qǐng)您輸入手機(jī)號(hào)碼:') password = input('請(qǐng)您輸入登錄密碼:') account = [] for i in b: account.append(int(i)) account.sort() b[str(account[-1] + 1)] = [password, name, gender, phone] time.sleep(0.5) print('注冊(cè)成功!') time.sleep(0.5) print('會(huì)員卡號(hào):{}、登錄密碼:{}、會(huì)員昵稱:{}、會(huì)員性別:{}、手機(jī)號(hào)碼:{}'.format (str(account[-1] + 1), password, name, gender,phone)) elif choose == '3': while True: delete = input('是否需要注銷會(huì)員(1.需要 2.取消):') if delete == '2': break cancel = input('請(qǐng)您輸入需要注銷會(huì)員卡號(hào):') if cancel not in b: print('卡號(hào)輸入有誤!') else: del b[cancel] time.sleep(0.5) print('會(huì)員注銷成功!') elif choose == '4': while True: query = input('請(qǐng)您選擇查詢操作(1.查詢個(gè)人 2.查詢?nèi)?nbsp;3.退出查詢):') if query == '1': query_personal = input('請(qǐng)您輸入需要查詢會(huì)員卡號(hào):') if query_personal in d: for i in d[query_personal]: time.sleep(0.5) print('會(huì)員卡號(hào):{}、會(huì)員昵稱:{}、購(gòu)票影片:{}、影廳座位:{}'.format (query_personal, b[query_personal][1], i, ' '.join(d[query_personal][i]))) else: print('未查詢到購(gòu)票信息!') elif query == '2': for x in d: for y in d[x]: if x in b: time.sleep(0.5) print('會(huì)員卡號(hào):{}、會(huì)員昵稱:{}、購(gòu)票影片:{}、影廳座位:{}'.format (x, b[x][1], y, ' '.join(d[x][y]))) else: time.sleep(0.5) print('會(huì)員卡號(hào):{}、會(huì)員昵稱:{}、購(gòu)票影片:{}、影廳座位:{}'.format (x, a[x][1], y, ' '.join(d[x][y]))) elif query == '3': break elif choose == '5': card_number = '' judge = input('是否有會(huì)員卡(1.有卡 2.無(wú)卡):') if judge == '1': card_number = input('請(qǐng)您輸入會(huì)員卡號(hào):') elif judge == '2': card_number = account time.sleep(0.5) print('*' * 3 + '電影放映表' + '*' * 3) for x, y in list(enumerate(c, 1)): print(x, y['name']) print('*' * 13) time.sleep(0.5) buy = int(input('請(qǐng)您選擇電影場(chǎng)次:')) print('*' * 8 + '電影信息' + '*' * 8) print('影名:{}'.format(c[buy - 1]['name'])) print('類別:{}'.format(c[buy - 1]['category'])) print('導(dǎo)演:{}'.format(c[buy - 1]['director'])) print('演員:{}'.format(c[buy - 1]['actor'])) print('*' * 23) while True: time.sleep(0.5) print('*' * 13 + '影廳座位' + '*' * 13) for i in c[buy - 1]['seat']: print(' '.join(i)) print('*' * 32) ticket = input('是否繼續(xù)購(gòu)票(1.繼續(xù) 2.退出):') if ticket == '2': break line_numbers = int(input('請(qǐng)您選擇影廳行號(hào):')) seat_numbers = int(input('請(qǐng)您選擇影廳座號(hào):')) if c[buy - 1]['seat'][line_numbers][seat_numbers] == '■': print('不好意思,座位已選!') else: c[buy - 1]['seat'][line_numbers][seat_numbers] = '■' time.sleep(0.5) print('購(gòu)票成功,電影名:{} 座位號(hào):{}排{}號(hào)'.format (c[buy - 1]['name'], line_numbers, seat_numbers)) if card_number in d and c[buy - 1]['name'] in d[card_number]: d[card_number][c[buy - 1]['name']].append( '{}排{}號(hào)'.format(line_numbers, seat_numbers)) elif card_number in d and c[buy - 1]['name'] not in d[card_number]: d[card_number][c[buy - 1]['name']] = [ '{}排{}號(hào)'.format(line_numbers, seat_numbers)] else: d[card_number] = { c[buy - 1]['name']: ['{}排{}號(hào)'.format(line_numbers, seat_numbers)]} elif choose == '6': while True: unsubscribe = input('是否需要退訂影票(1.需要 2.退出):') if unsubscribe == '2': break else: card_number = input('請(qǐng)您輸入會(huì)員卡號(hào):') for i in d[card_number]: if card_number in b: time.sleep(0.5) print('卡號(hào):{} 昵稱:{} 影名:{} 座位:{}'.format (card_number, b[card_number][1], i, ' '.join(d[card_number][i]))) else: time.sleep(0.5) print('卡號(hào):{} 昵稱:{} 影名:{} 座位:{}'.format (card_number, a[card_number][1], i, ' '.join(d[card_number][i]))) name = dict(enumerate(d[card_number], 1)) for i in name: print(i, name[i]) movie_number = int(input('請(qǐng)您選擇需要退票電影序號(hào):')) number = dict(enumerate(d[card_number][name[movie_number]], 1)) for i in number: print(i, number[i]) seat_number = int(input('請(qǐng)您選擇需要退票電影座位:')) message = re.findall(r'\d+', number[seat_number]) for i in c: if name[movie_number] == i['name']: i['seat'][int(message[0])][int(message[1])] = '□' d[card_number][name[movie_number]].remove(number[seat_number]) time.sleep(0.5) print('退票成功!') if not d[card_number][name[movie_number]]: del d[card_number][name[movie_number]] elif choose == '7': more_ticket = [] for x in range(len(c)): number = 0 for y in c[x]['seat']: number += y.count('□') more_ticket.append(number) time.sleep(0.5) print('影名:{}-余票:{}張'.format(c[x]['name'], more_ticket[x])) elif choose == '8': while True: options = input('請(qǐng)您選擇操作選項(xiàng)(1.添加管理 2.刪除管理 3.退出系統(tǒng)):') if options == '1': name = input('請(qǐng)您輸入管理昵稱:') gender = input('請(qǐng)您輸入管理性別:') phone = input('請(qǐng)您輸入手機(jī)號(hào)碼:') password = input('請(qǐng)您輸入登錄密碼:') account = [] for i in a: account.append(int(i)) account.sort() a[str(account[-1] + 1)] = [password, name, gender, phone] time.sleep(0.5) print('注冊(cè)成功!') time.sleep(0.5) print('管理賬號(hào):{}、登錄密碼:{}、管理昵稱:{}、管理性別:{}、手機(jī)號(hào)碼:{}'.format (str(account[-1] + 1), password, name, gender, phone)) elif options == '2': while True: delete = input('是否繼續(xù)刪除管理員(1.繼續(xù) 2.退出):') if delete == '2': break else: card = input('請(qǐng)您輸入刪除管理員卡號(hào):') del a[card] time.sleep(0.5) print('刪除成功!') elif options == '3': break elif choose == '9': while True: options = input('請(qǐng)您選擇操作選項(xiàng)(1.添加影片 2.刪除影片 3.退出系統(tǒng)):') if options == '1': name = input('請(qǐng)您輸入影名:') category = input('請(qǐng)您輸入類別:') director = input('請(qǐng)您輸入導(dǎo)演:') actor = input('請(qǐng)您輸入演員:') seat = [[' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' '], ['1', '□', '□', '□', '□', '□', '□', '□', '□', '□', '1'], ['2', '□', '□', '□', '□', '□', '□', '□', '□', '□', '2'], ['3', '□', '□', '□', '□', '□', '□', '□', '□', '□', '3'], ['4', '□', '□', '□', '□', '□', '□', '□', '□', '□', '4'], ['5', '□', '□', '□', '□', '□', '□', '□', '□', '□', '5'], ['6', '□', '□', '□', '□', '□', '□', '□', '□', '□', '6'], [' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ']] c.append({'name': name, 'category': category, 'director': director, 'actor': actor, 'seat': seat}) time.sleep(0.5) print('添加影片成功!') elif options == '2': for x, y in list(enumerate(c, 1)): print(x, y['name']) delete = int(input('請(qǐng)您選擇需要?jiǎng)h除影片序號(hào):')) c.pop(delete - 1) time.sleep(0.5) print('影片刪除成功!') elif options == '3': break elif choose == '10': sales_ticket = [] for x in range(len(c)): number = 0 for y in c[x]['seat']: number += y.count('■') sales_ticket.append(number) time.sleep(0.5) print('影名:{}-售出:{}張'.format(c[x]['name'], sales_ticket[x])) elif choose == '11': print('管理卡號(hào):{}、管理昵稱:{}、管理性別:{}、手機(jī)號(hào)碼:{}'.format (account, a[account][1], a[account][2], a[account][3])) while True: continues = input('是否需要修改信息(1.需要 2.退出)') if continues == '2': break else: modify = input('請(qǐng)您選擇修改選項(xiàng)(1.管理昵稱 2.管理性別 3.手機(jī)號(hào)碼):') if modify == '1': a[account][1] = input('請(qǐng)您輸入管理昵稱:') elif modify == '2': a[account][2] = input('請(qǐng)您輸入管理性別:') elif modify == '3': a[account][3] = input('請(qǐng)您輸入手機(jī)號(hào)碼:') time.sleep(0.5) print('信息修改成功!') elif choose == '12': break else: print('密碼錯(cuò)誤,登錄失?。?#39;) else: print('賬號(hào)錯(cuò)誤,請(qǐng)您核對(duì)!')
3.用戶登錄
import re, time def users_login(x, y, z): account = input('請(qǐng)您輸入賬號(hào):') password = input('請(qǐng)您輸入密碼:') if account in x: if x[account][0] == password: time.sleep(0.5) print('密碼正確,登錄成功!') while True: operation = input('請(qǐng)您選擇操作(1.會(huì)員信息 2.購(gòu)買影票 3.購(gòu)票信息 4.影票退訂 5.修改信息 6.退出系統(tǒng)):') if operation == '1': time.sleep(0.5) print('*' * 7 + '會(huì)員信息' + '*' * 7) print('會(huì)員卡號(hào):{}'.format(account)) print('會(huì)員昵稱:{}'.format(x[account][1])) print('會(huì)員性別:{}'.format(x[account][2])) print('手機(jī)號(hào)碼:{}'.format(x[account][3])) print('*' * 21) elif operation == '2': time.sleep(0.5) print('*' * 3 + '電影放映表' + '*' * 3) for a, b in list(enumerate(y, 1)): print(a, b['name']) print('*' * 13) buy = int(input('請(qǐng)您選擇電影場(chǎng)次:')) time.sleep(0.5) print('*' * 8 + '電影信息' + '*' * 8) print('影名:{}'.format(y[buy - 1]['name'])) print('類別:{}'.format(y[buy - 1]['category'])) print('導(dǎo)演:{}'.format(y[buy - 1]['director'])) print('演員:{}'.format(y[buy - 1]['actor'])) print('*' * 23) while True: time.sleep(0.5) print('*' * 13 + '影廳座位' + '*' * 13) for i in y[buy - 1]['seat']: print(' '.join(i)) print('*' * 32) choose = input('是否繼續(xù)購(gòu)票(1.繼續(xù) 2.退出):') if choose == '2': break line_numbers = int(input('請(qǐng)您選擇影廳行號(hào):')) seat_numbers = int(input('請(qǐng)您選擇影廳座號(hào):')) if y[buy - 1]['seat'][line_numbers][seat_numbers] == '■': print('不好意思,座位已選!') else: y[buy - 1]['seat'][line_numbers][seat_numbers] = '■' time.sleep(0.5) print('購(gòu)票成功,電影名:{} 座位號(hào):{}排{}號(hào)'.format(y[buy - 1]['name'], line_numbers, seat_numbers)) if account in z and y[buy - 1]['name'] in z[account]: z[account][y[buy - 1]['name']].append( '{}排{}號(hào)'.format(line_numbers, seat_numbers)) elif account in z and y[buy - 1]['name'] not in z[account]: z[account][y[buy - 1]['name']] = [ '{}排{}號(hào)'.format(line_numbers, seat_numbers)] else: z[account] = { y[buy - 1]['name']: ['{}排{}號(hào)'.format(line_numbers, seat_numbers)]} elif operation == '3': if account in z: for i in z[account]: time.sleep(0.5) print('卡號(hào):{} 昵稱:{} 影名:{} 座位:{}'.format (account, x[account][1], i,' '.join(z[account][i]))) else: print('未查詢到購(gòu)票信息') elif operation == '4': if account in z: for i in z[account]: time.sleep(0.5) print('卡號(hào):{} 昵稱:{} 影名:{} 座位:{}'.format(account, x[account][1], i, ' '.join(z[account][i]))) print('未查詢到訂票信息') while True: unsubscribe = input('是否需要退訂影票(1.需要 2.退出):') if unsubscribe == '2': break else: name = dict(enumerate(z[account], 1)) for i in name: print(i, name[i]) movie_number = int(input('請(qǐng)您選擇需要退票電影序號(hào):')) number = dict(enumerate(z[account][name[movie_number]], 1)) for i in number: print(i, number[i]) seat_number = int(input('請(qǐng)您選擇需要退票電影座位:')) message = re.findall(r'\d+', number[seat_number]) for i in y: if name[movie_number] == i['name']: i['seat'][int(message[0])][int(message[1])] = '□' z[account][name[movie_number]].remove(number[seat_number]) time.sleep(0.5) print('退票成功!') if not z[account][name[movie_number]]: del z[account][name[movie_number]] elif operation == '5': time.sleep(0.5) print('*' * 7 + '會(huì)員信息' + '*' * 7) print('會(huì)員卡號(hào):{}'.format(account)) print('會(huì)員昵稱:{}'.format(x[account][1])) print('會(huì)員性別:{}'.format(x[account][2])) print('手機(jī)號(hào)碼:{}'.format(x[account][3])) print('*' * 21) while True: modify = input('是否繼續(xù)修改(1.繼續(xù) 2.退出):') if modify == '2': break choose = input('請(qǐng)您選擇修改內(nèi)容(1.會(huì)員昵稱 2.會(huì)員性別 3.手機(jī)號(hào)碼):') if choose == '1': x[account][1] = input('請(qǐng)輸入會(huì)員昵稱:') elif choose == '2': x[account][2] = input('請(qǐng)輸入會(huì)員性別:') elif choose == '3': x[account][3] = input('請(qǐng)輸入手機(jī)號(hào)碼:') elif operation == '6': print('系統(tǒng)退出成功,歡迎下次使用!') break else: print('密碼錯(cuò)誤,登錄失??!') else: print('賬號(hào)錯(cuò)誤,請(qǐng)您核對(duì)!')
4.注冊(cè)用戶
def registered(x): name = input('請(qǐng)您輸入會(huì)員昵稱:') gender = input('請(qǐng)您輸入會(huì)員性別:') phone = input('請(qǐng)您輸入手機(jī)號(hào)碼:') password = input('請(qǐng)您輸入登錄密碼:') account = [] for i in x: account.append(int(i)) account.sort() x[str(account[-1] + 1)] = [password, name, gender, phone] print('注冊(cè)成功!') print('會(huì)員卡號(hào):{}、登錄密碼:{}、會(huì)員昵稱:{}、會(huì)員性別:{}、手機(jī)號(hào)碼:{}'.format (str(account[-1] + 1), password, name, gender, phone))
5.找回密碼
def back(x, y): account = input('請(qǐng)您輸入登錄賬號(hào):') if account in x: while True: need = input('是否需要找回密碼(1.需要 2.取消):') if need == '2': break phone = input('請(qǐng)您輸入預(yù)留手機(jī)號(hào)碼:') if phone == x[account][3]: x[account][0] = input('請(qǐng)您輸入新密碼:') print('號(hào)碼正確,修改成功!') else: print('號(hào)碼錯(cuò)誤,請(qǐng)您核實(shí)!') elif account in y: while True: need = input('是否需要找回密碼(1.需要 2.取消):') if need == '2': break phone = input('請(qǐng)您輸入預(yù)留手機(jī)號(hào)碼:') if phone == y[account][3]: y[account][0] = input('請(qǐng)您輸入新密碼:') print('號(hào)碼正確,修改成功!') else: print('號(hào)碼錯(cuò)誤,請(qǐng)您核實(shí)!') else: print('賬號(hào)錯(cuò)誤,請(qǐng)您核對(duì)!')
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。