Python電影售票系統(第三個小程式)

專注的阿熊發表於2021-12-27

import re, time

def users_login(x, y, z):

     account = input(' 請您輸入賬號: ')

     password = input(' 請您輸入密碼: ')

     if account in x:

         if x[account][0] == password:

             time.sleep(0.5)

             print(' 密碼正確,登入成功! ')

             while True:

                 operation = input(' 請您選擇操作( 1. 會員資訊 2. 購買影票 3. 購票資訊 4. 影票退訂 5. 修改資訊 6. 退出系統) :')

                 if operation == '1':

                     time.sleep(0.5)

                     print('*' * 7 + ' 會員資訊 ' + '*' * 7)

                     print(' 會員卡號 :{}'.format(account))

                     print(' 會員暱稱 :{}'.format(x[account][1]))

                     print(' 會員性別 :{}'.format(x[account][2]))

                     print(' 手機號碼 :{}'.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(' 請您選擇電影場次: '))

                     time.sleep(0.5)

                     print('*' * 8 + ' 電影資訊 ' + '*' * 8)

                     print(' 影名: {}'.format(y[buy - 1]['name']))

                     print(' 類別: {}'.format(y[buy - 1]['category']))

                     print(' 導演: {}'.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(' 是否繼續購票( 1. 繼續 2. 退出): ')

                         if choose == '2':

                             break

                         line_numbers = int(input(' 請您選擇影廳行號: '))

                         seat_numbers = int(input(' 請您選擇影廳座號: '))

                         if y[buy - 1]['seat'][line_numbers][seat_numbers] == ' ':

                             print(' 不好意思,座位已選! ')

                         else:

                             y[buy - 1]['seat'][line_numbers][seat_numbers] = ' '

                             time.sleep(0.5)

                             print(' 購票成功,電影名 :{} 座位號 :{} {} '.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(

                                     '{} {} '.format(line_numbers, seat_numbers))

                             elif account in z and y[buy - 1]['name'] not in z[account]:

                                 z[account][y[buy - 1]['name']] = [

                                     '{} {} '.format(line_numbers, seat_numbers)]

                             else:

                                 z[account] = {

                                     y[buy - 1]['name']: ['{} {} '.format(line_numbers, seat_numbers)]}

                 elif operation == '3':

                     if account in z:

                         for i in z[account]:

                             time.sleep(0.5)

                             print(' 卡號 :{} 暱稱 :{} 影名 :{} 座位 :{}'.format

                                   (account, x[account][1], i,' '.join(z[account][i])))

                     else:

                         print(' 未查詢到購票資訊 ')

                 elif operation == '4':

                     if account in z:

                         for i in z[account]:

                             time.sleep(0.5)

                             print(' 卡號 :{} 暱稱 :{} 影名 :{} 座位 :{}'.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, 外匯跟單gendan5.comname[i])

                             movie_number = int(input(' 請您選擇需要退票電影序號: '))

                             number = dict(enumerate(z[account][name[movie_number]], 1))

                             for i in number:

                                 print(i, number[i])

                             seat_number = int(input(' 請您選擇需要退票電影座位: '))

                             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 + ' 會員資訊 ' + '*' * 7)

                     print(' 會員卡號 :{}'.format(account))

                     print(' 會員暱稱 :{}'.format(x[account][1]))

                     print(' 會員性別 :{}'.format(x[account][2]))

                     print(' 手機號碼 :{}'.format(x[account][3]))

                     print('*' * 21)

                     while True:

                         modify = input(' 是否繼續修改( 1. 繼續 2. 退出): ')

                         if modify == '2':

                             break

                         choose = input(' 請您選擇修改內容( 1. 會員暱稱 2. 會員性別 3. 手機號碼): ')

                         if choose == '1':

                             x[account][1] = input(' 請輸入會員暱稱 :')

                         elif choose == '2':

                             x[account][2] = input(' 請輸入會員性別 :')

                         elif choose == '3':

                             x[account][3] = input(' 請輸入手機號碼 :')

                 elif operation == '6':

                     print(' 系統退出成功,歡迎下次使用! ')

                     break

         else:

             print(' 密碼錯誤,登入失敗! ')

     else:

         print(' 賬號錯誤,請您核對! ')


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69946337/viewspace-2849577/,如需轉載,請註明出處,否則將追究法律責任。

相關文章