You are setting up a travel agency at a tourist resort. Your agency organizes we
ID: 3829992 • Letter: Y
Question
You are setting up a travel agency at a tourist resort. Your agency organizes weekly bus tours. There is one tour on each day of the weekend and each tour has exactly 5 seats. Write a program for your agency to implement the weekly reservation of seats. The program should repeatedly execute one of the following commands: Book This operation should ask the user for a day (Saturday or Sunday) and check if there is a seat in the user input day. If there is one. the program should remember that one more seat has been reserved for that day. Otherwise, the program should print that there is "No More Seats Left". Cancel: This operation should ask the user for a day (Saturday or Sunday) and cancel one reservation for the given day and remember that there is one more seat free. If no seats were reserved that day, you program should print "No reservation made on this day. Switch: This operation switches one reservation from one day. D1 (Saturday or Sunday) to another day. D2 (Saturday or Sunday). In this case the number of reserved seats in D1 is decremented by 1 and the number of reserved seats in 02 is incremented by one. Note that if no seats were reserved in 01 or if there is no more available seat on 02. your program should print "No sear available to switch". Report: Print the number of available seats in each day. Quit: Exit the system.Explanation / Answer
Python 2 code:
import sys
Availability_sat = 5;
Availability_sun = 5;
while(True):
print "Enter 1.To Book a seat" , " ","2.Cancel" , " ", "3.Switch" , " ", "4.Report 5.Quit"
c = int(raw_input().strip())
if(c == 1):
print("Please enter 1 to book on saturday and 2 for sunday")
n = int(raw_input().strip())
if(n==1):
if(Availability_sat >=1):
print "Seat booked on saturday"
Availability_sat = Availability_sat - 1
else:
print "No Seats Available on saturday"
elif(n==2):
if(Availability_sun >=1):
print "Seat booked on sunday"
Availability_sun = Availability_sun - 1
else:
print "No Seats Available on sunday"
elif(c == 2):
print("Please enter 1 to Cancel on saturday and 2 for sunday")
n = int(raw_input().strip())
if(n==1):
if(Availability_sat < 5):
print "Seat Canceld on saturday"
Availability_sat = Availability_sat + 1
else:
print "No Seats booked yet on saturday"
elif(n==2):
if(Availability_sun < 5):
print "Seat Canceld on sunday"
Availability_sun = Availability_sun + 1
else:
print "No Seats booked yet on sunday"
elif(c == 3):
print("Please enter 1 to Switch from saturday to sunday")
print("Please enter 2 to Switch from sunday to saturday")
n = int(raw_input().strip())
if(n==1):
if( Availability_sun >=1 and Availability_sat < 5):
print "1 Seat Switched from saturday to sunday"
Availability_sat = Availability_sat + 1
Availability_sun = Availability_sun - 1
else:
print "No Seat Available to Switch"
elif(n==2):
if( Availability_sat >=1 and Availability_sun < 5):
print "1 Seat Switched from sunday to saturday"
Availability_sat = Availability_sat - 1
Availability_sun = Availability_sun + 1
else:
print "No Seat Available to Switch"
elif(c == 4):
print "Availability on saturday", Availability_sat
print "Availability on sunday", Availability_sun
elif(c == 5):
sys.exit()
else:
print("Invalid input")
Sample Output:
Enter
1.To Book a seat
2.Cancel
3.Switch
4.Report
5.Quit
1
Please enter 1 to book on saturday and 2 for sunday
1
Seat booked on saturday
Enter
1.To Book a seat
2.Cancel
3.Switch
4.Report
5.Quit
4
Availability on saturday 4
Availability on sunday 5
Enter
1.To Book a seat
2.Cancel
3.Switch
4.Report
5.Quit
1
Please enter 1 to book on saturday and 2 for sunday
2
Seat booked on sunday
Enter
1.To Book a seat
2.Cancel
3.Switch
4.Report
5.Quit
4
Availability on saturday 4
Availability on sunday 4
Enter
1.To Book a seat
2.Cancel
3.Switch
4.Report
5.Quit
2
Please enter 1 to Cancel on saturday and 2 for sunday
1
Seat Canceld on saturday
Enter
1.To Book a seat
2.Cancel
3.Switch
4.Report
5.Quit
4
Availability on saturday 5
Availability on sunday 4
Enter
1.To Book a seat
2.Cancel
3.Switch
4.Report
5.Quit
2
Please enter 1 to Cancel on saturday and 2 for sunday
2
Seat Canceld on sunday
Enter
1.To Book a seat
2.Cancel
3.Switch
4.Report
5.Quit
4
Availability on saturday 5
Availability on sunday 5
Enter
1.To Book a seat
2.Cancel
3.Switch
4.Report
5.Quit
2
Please enter 1 to Cancel on saturday and 2 for sunday
2
No Seats booked yet on sunday
Enter
1.To Book a seat
2.Cancel
3.Switch
4.Report
5.Quit
5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.