forked from tarunsinghofficial/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoom_Booking
158 lines (113 loc) · 3.86 KB
/
Room_Booking
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import json
def room_check(num,arr,dept):
'''
It checks whether the room can be booked if it does not lie in the given timeframe.
'''
if num in range(arr,dept):
return True
else:
return False
def on_choice():
'''
It decides whether or not to continue room booking.
'''
choice = 'wrong'
while choice not in ['Y', 'N']:
choice = input("Want to keep Booking Rooms: (Y/N) ")
if choice not in ['Y', 'N']:
print("Sorry, I don't Understand Please Choose Y or N")
if choice == 'Y':
return True
else:
return False
def user_choice_arr():
'''
Enters the user Input with validation on Arrival Time.
'''
choice = 'wrong'
acceptable_range = range(0,24)
within_range = False
#Two Conditions to check
#It should be a digit and within range
while choice.isdigit() == False or within_range == False:
choice = input("Please Enter the Arrival Time (0-24): ")
#Digit Check
if choice.isdigit() == False:
print("Sorry that is not a digit")
#Range Check
if choice.isdigit() == True:
if int(choice) in acceptable_range:
within_range = True
else:
print("Sorry not in Acceptable Range")
within_range = False
return int(choice)
def user_choice_dept():
'''
Enters the user Input with validation on Departure Time.
'''
choice = 'wrong'
acceptable_range = range(0,24)
within_range = False
#Two Conditions to check
#It should be a digit and within range
while choice.isdigit() == False or within_range == False:
choice = input("Please Enter the Departure Time (0-24): ")
#Digit Check
if choice.isdigit() == False:
print("Sorry that is not a digit")
#Range Check
if choice.isdigit() == True:
if int(choice) in acceptable_range:
within_range = True
else:
print("Sorry not in Acceptable Range")
within_range = False
return int(choice)
#Control Flow starts from here
with open('test.json','w') as f:
x = {} #Empty Dictionary -> Object
x['Users'] = [] #Empty List -> array
book_on = True
print("\t\t\t\tWelcome to Datopic Hotel ")
l_arr = []
l_dept = []
pname = input("Please Enter Your Name: ")
print("Welcome Mr.\Ms. {} to the Datopic Hotel, For How much duration would you like to stay with us".format(pname))
parr = user_choice_arr()
l_arr.append(parr)
pdept = user_choice_dept()
l_dept.append(pdept)
#JSON Appending List in Dict
x['Users'].append({'Name': pname, 'Arrival': parr, 'Departure': pdept})
tot_time = pdept-parr
if tot_time < 1:
print("We have Minimum Booking of 1 Hour")
else:
print("Your duration at our Hotel Would be {} hours. Enjoy Your Stay!".format(tot_time))
#Python Object -> JSON Object
json.dump(x , f)
with open('test.json','w') as f:
while book_on == True:
pname = input("Please Enter Your Name: ")
print("Welcome Mr.\Ms. {} to the Datopic Hotel, For How much duration would you like to stay with us".format(pname))
parr = user_choice_arr()
if room_check(parr, l_arr[-1],l_dept[-1]) == True:
print("Room Cannot be booked as our Inventory is Full, You can register for any other time with us. Sorry for Inconvenience")
continue
l_arr.append(parr)
pdept = user_choice_dept()
if room_check(parr, l_arr[-1],l_dept[-1]) == True:
print("Room Cannot be booked as our Inventory is Full, You can register for any other time with us. Sorry for Inconvenience")
continue
l_dept.append(pdept)
#JSON Appending List in Dict
x['Users'].append({'Name': pname, 'Arrival': parr, 'Departure': pdept})
tot_time = pdept-parr
if tot_time < 1:
print("We have Minimum Booking of 1 Hour")
else:
print("Your duration at our Hotel Would be {} hours. Enjoy Your Stay!".format(tot_time))
book_on = on_choice()
#Python Object -> JSON Object
json.dump(x , f)