根据用户输入修改数组

发布于 2025-01-11 15:09:06 字数 440 浏览 0 评论 0原文

对于我的任务,我们目前正在编写一个酒店预订系统。对于预订的每个房间,我希望将之前在选择时可用的房间从数组中删除。 这是我的数组: availableRooms[38, 48, 64, 89, 110, 134, 224, 306, 402]

所以它几乎涉及顺序文件读取和写入,我的伙伴就像 Python Kami 告诉我我应该这样做创建一个单独的txt文件,如下,0表示可用,1表示不可用:

0, 0, 0, 0, 0, 0, 0, 0, 0 拆分时 = [0, 0, 0, 0, 0, 0, 0, 0, 0]

因此,如果我选择房间 38,该数组中的第一个零将变成 1,并且它将从 availableNumbers 数组中删除所述房间...我认为。

如果有人能够为我提供帮助或代码来指导我如何做到这一点,我们将非常感谢您的支持,因为任务的截止日期越来越近。

For my assignment, we are currently coding a hotel booking system. For each room booked I want to make it so that a room that was previously available when selected is eliminated from the array.
This is my array:
availableRooms[38, 48, 64, 89, 110, 134, 224, 306, 402]

So pretty much it involves sequential file reading and writing and my mate who is like a Python Kami told me I should create a separate txt file as follows with 0 meaning available and 1 meaning unavailable:

0, 0, 0, 0, 0, 0, 0, 0, 0
when split
= [0, 0, 0, 0, 0, 0, 0, 0, 0]

So if I were to pick room 38, the first zero in this array would turn into a 1 and it would remove said room from the availableNumbers array...I think.

If anyone is able to provide me with assistance or code in how to do so, your support would be greatly appreciated as the deadline for the assignment is nearing closer and closer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们的影子 2025-01-18 15:09:06
allRooms = [38, 48, 64, 89, 110, 134, 224, 306, 402]
availableRooms = [38, 48, 64, 89, 110, 134, 224, 306, 402] # Your array

selected = input("What room would you like? These are the available rooms: ", availableRooms) # Asks user to input room

for 0 to len(availableRooms): # For all values of the array
    arrayPosition = 0
    if selected == availableRooms[arrayPosition]: # If "selected" is the position
        del availableRooms[arrayPosition] # delete it from "availableRooms"
    else:
        arrayPosition = arrayPosition + 1

if len(availableRooms) = len(allRooms): # If unsuccessful input
    print("You have not selected a valid room.")
    break
else:
    print("You have booked Room ", selected ". Enjoy your stay!")
allRooms = [38, 48, 64, 89, 110, 134, 224, 306, 402]
availableRooms = [38, 48, 64, 89, 110, 134, 224, 306, 402] # Your array

selected = input("What room would you like? These are the available rooms: ", availableRooms) # Asks user to input room

for 0 to len(availableRooms): # For all values of the array
    arrayPosition = 0
    if selected == availableRooms[arrayPosition]: # If "selected" is the position
        del availableRooms[arrayPosition] # delete it from "availableRooms"
    else:
        arrayPosition = arrayPosition + 1

if len(availableRooms) = len(allRooms): # If unsuccessful input
    print("You have not selected a valid room.")
    break
else:
    print("You have booked Room ", selected ". Enjoy your stay!")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文