I'm trying to create a program that will assign a hotel room number to the guests. After it is assigned, inside the dictionary, the value for the key should be updated into either 'Unavailable' or 'Reserved'. But, the thing is, after I close the program. Those room numbers that were updated becomes back into 'Available'.
Is there a way to change the value, so that it stays updated even after I close the program?
import math
f = open('room.txt', 'r+')
#Hotel Rooms
for i in range(1, 7):
locals()['Level{}'.format(i)] = {} # Creating Dictionary
start = 101
for x in range(1, 7):
for i in range(start, start + 10):
eval("Level" + str(x))[i] = 'Available' # Adding Values into Dictionary
start += 100
# heading function
def heading(number, header):
for i in range(60):
print('-', end = '')
print()
for i in range(number):
print('*', end = ' ')
print('\n' + header)
for i in range(number):
print('*', end = ' ')
print()
# customer details function
def customer():
print('''Room Types:
1 --> Single (Level 1)
2 --> Double (Level 2)
3 --> Triple (Level 3)
4 --> Quad (Level 4)
5 --> Queen (Level 5)
6 --> King (Level 6)
''')
room = input('Room Type: ')
name = input('Name: ')
hp = input('Mobile Number: ')
guests = input('Number of Guests: ')
arrival = input('Arrival Date(dd/mm/yyyy): ')
departure = input('Departure Date(dd/mm/yyyy): ')
confirm = input('Confirmation(Y/N): ')
conf(confirm, room, option)
# confirmation function + room for guest
def conf(con, num, opt):
if con == 'Y':
try:
for level, availability in eval('Level' + str(num)).items():
if availability == 'Available':
print('Guest Room Number:', level)
if option == '1':
eval('Level' + str(num))[level] = 'Reserved'
elif option == '2':
eval('Level' + str(num))[level] = 'Unavailable'
print('\nRoom Recorded!')
break
for i in range(1, 7):
f.write('Level ' + str(i) + '\n')
for key in eval('Level' + str(i)):
f.write(str(key) + ": " + eval('Level' + str(i))[key] + '\n')
f.write('\n')
f.close()
except NameError:
print('\nInvalid Room Type.')
elif con == 'N':
print('\nRecord Not Recorded.')
else:
print('\nInvalid Confirmation.')
# sub-headings (options)
def options():
print('''
Choose one of the following options (0-3):
0 <-- Back to Main Menu.
1 --> Booking Engine
2 --> Check In
3 --> Check Out''')
while True:
cus = '* Customer Registration *'
num = math.ceil(len(cus)/2)
heading(num, cus)
options()
option = input('Enter your option: ')
# Booking Engine
if option == '1':
boo = '* Booking Engine *'
num = math.ceil(len(boo)/2)
heading(num, boo)
customer()
#Check In
elif option == '2':
chein = '* Check In *'
num = math.ceil(len(chein)/2)
heading(num, chein)
customer()
else:
print("\nInvalid Option.")
continue