Advertisement
Sayach8

Untitled

Apr 27th, 2025 (edited)
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | Source Code | 0 0
  1. def is_valid_num(num):
  2.   NUMBERS = ["0","1","2","3","4","5","6","7","8","9"]
  3.   SIGNS = ["+","-"]
  4.   for i in range(len(num)):
  5.     if i==0:
  6.       if num[i] not in SIGNS+NUMBERS:
  7.         return False
  8.     elif num[i] not in NUMBERS:
  9.       return False
  10.  
  11.   return True
  12.  
  13. print("""
  14. Available Seats: 50
  15. Business Class: Rs.15000 per seat
  16. Economy Class: Rs.7500 per seat
  17. """)
  18.  
  19. TOTAL_SEAT = 50
  20. remaining_seat=50
  21.  
  22. while True:
  23.   seat_type = input("Enter class (Business|Economy) for reservation:\n")
  24.   if seat_type != "Business" and seat_type != "Economy":
  25.     print("Invalid class choice. Please enter Business or Economy.")
  26.     continue
  27.  
  28.   per_seat_cost=7500
  29.   if seat_type=="Business":
  30.     per_seat_cost = 15000
  31.  
  32.   num_seat = input("Enter the number of seats to reserve: ")
  33.   if not is_valid_num(num_seat):
  34.     print("Invalid input. Please enter a valid number.")
  35.     continue
  36.  
  37.   if int(num_seat)>remaining_seat:
  38.     print(f"Invalid number of seats. Available seats: {remaining_seat}")
  39.   else:
  40.     num_seat = int(num_seat)
  41.     remaining_seat-=num_seat
  42.  
  43.     print(f"Reservation successful! Total cost: Rs.{num_seat*per_seat_cost}")
  44.  
  45.   reserve_again = input("Do you want to make another reservation?\n(yes|no): ")
  46.   if reserve_again == "yes":
  47.     continue
  48.   else:
  49.     break
  50.  
  51. print("Boarding Passes:")
  52. for i in range(TOTAL_SEAT-remaining_seat):
  53.   print(f"Seat {i+1} - Boarding Pass")
  54.  
  55. print("Thank you for using our reservation system!")
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement