Techtalks: Traveltech

how can I store multiple travelers information during booking using loop?

I want to store multiple travelers information during booking using loop , i am using Amadeus Nodejs sdk please guide me.

image placeholder
anonymous

asked  Oct 6, 2020

7763views
1answer
0votes
image placeholder
Jack Smith, Software Developer at Accenture

answered  Feb 12, 2024

0

Hello,

To store multiple travelers' information during booking using a loop, you can use a data structure like a list in Python. Here's a basic example using a loop to collect information for multiple travelers:

# Initialize an empty list to store traveler information
travelers = []

# Define the number of travelers
num_travelers = int(input("Enter the number of travelers: "))

# Loop through each traveler
for i in range(1, num_travelers + 1):
    print(f"Enter information for traveler {i}:")
    name = input("Name: ")
    age = int(input("Age: "))
    passport_number = input("Passport Number: ")
    
    # Store the traveler information as a dictionary
    traveler_info = {
        "Name": name,
        "Age": age,
        "Passport Number": passport_number
    }
    
    # Append the traveler information to the list
    travelers.append(traveler_info)

# Print the collected traveler information
print("\nTraveler Information:")
for traveler in travelers:
    print(traveler)