2

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.

bradmate
  • 41
  • 1
  • what have you tried so far please ? – D.L Mar 04 '22 at 10:26
  • @D.L so far I haven't really tried anything, because im unsure how to act upon the idea – bradmate Mar 04 '22 at 11:10
  • 1
    okay, generally speaking you might wish to follow this guide: https://stackoverflow.com/help/minimal-reproducible-example this way users can see which part of the question that you are stuck on and step in to help you. – D.L Mar 04 '22 at 11:27

1 Answers1

0
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!")
taylor.2317
  • 582
  • 1
  • 9
  • 23