鱼C论坛

 找回密码
 立即注册
查看: 2945|回复: 1

订座系统

[复制链接]
发表于 2022-9-11 17:03:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
各位高手,有个电影院订座的作业,请您帮手:
1. 60座位影院。。
2. 向客人展示座位,并请客户选择位置
3. 可同时选择多个座位
4. 如座位不可用,给客户信息并请他重选
5. 最好可以用上map 和 try-except-else
6. 最后告知售票的数量、上座率和已经赚取的收入。
7.有方法预防客人选择不可用的座位。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-9-11 22:52:26 | 显示全部楼层
请高手帮忙检查一下,并加上最后的6、7项次。感谢!
# Ticket Booking System.
def print_tickets():
    """Print the tickets of the user."""
    for user_name, seats in user_tickets.items():
        print(f"\nYou, {user_name.title()}, have chosen {len(seats)} seat(s).")
        for seat in seats:
            print(f"\tSeat number: {seat}")


# Empty dictionary to store info later on.
user_tickets = {}

# List of seats the user can choose from.
available_seats = ['1a', '2a', '10b', '10d', '10e', '10g', '10f', '8f', '8a', '9g' ]


# All prompts.
start_prompt = "\nWould you like to start booking your ticket? (yes/no) "
wanted_seats_prompt = "\nHow many seats are you booking today?"
wanted_seats_prompt += "\nEnter the number: "
name_prompt = "What is your name? "
seat_prompt = "\nPlease enter the number of the seat you would like to book: "
go_again_prompt = "Would you like to let someone else book their tickets? (yes/no) "


print("Welcome To The Seat Booking Portal!")

# Ask the user if he would like to start booking their tickets.
start = input(start_prompt)
if start.lower() == 'yes':
    # Runs until it reaches a break statement.
    while True:
        # Empty list to store the seat(s) the user has chosen.
        seats = []

        # Find out how many times to run the while loop.
        wanted_seats = input(wanted_seats_prompt)
        # Convert the string representation of the number to an integer representation.
        wanted_seats = int(wanted_seats)
        # If the user has asked for more seats than the number of seats
        # available execute this block.
        if wanted_seats > len(available_seats):
            print(f"\n--I'm sorry, we only have {len(available_seats)} "
                "seats available--")
            print("--Please try again--")
            continue

        # Ask for the users name.
        user_name = input(name_prompt)

        # Run until the user has chosen the requested number of seats.
        while True:

            # Show the user the available seats.
            print("\nHere are the available seats:")
            for seat in available_seats:
                print(seat)

            # Ask the user for their chosen seat number.
            seat = input(seat_prompt)

            # If the user has entered a seat that is in the 'available_seats'
            # list; remove it from the 'available_seats' list.
            if seat in available_seats:
                available_seats.remove(seat)
            # The user has entered a seat that is not in the 'avialbe_seats' list.
            # Ask for their seat again.
            else:
                print("\n--I'm sorry you have chosen an invalid seat--"
                    "\n-Please try again-")
                continue

            # Add the chosen seat to the 'seats' list
            seats.append(seat)

            # If the user has said that they are going to book more than one seat
            # go through this seat booking 'while' loop again.
            if wanted_seats > 1:
                print("\nYou can now choose another seat.")
                # The loop will run a limited number of times.
                # It will only 'continue' when there is more than one 'wanted_seat'.
                wanted_seats-=1
                continue
            else:
                break

        # Add the 'user_name' variable and 'seats' list to the 'user_tickets' dictionary.
        user_tickets[user_name] = seats

        #If their are any available seats left ask the user if he
        # wants to let another person book their tickets.
        if available_seats:
            go_again = input(go_again_prompt)
            if go_again == 'no':
                break
        else:
            break

    print_tickets()
    print("\nWe will now redirect you to the payment portal."
        "\nThank You for choosing us.")

else:
    print("You can always come by later!")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-26 03:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表