Luxury transport service offers luxurious travel facilities to passengers. At the time of ticket booking, the passengers have to give their details like name, age, gender, aadhaar number, pickup location and destination location. You are free to use any of the collection types to store passengers’ details. Write a user-defined function in python:To display the count of male and female passengers.To fetch the passenger details for a specific pickup location. If that location is not found, print “not found”. Else, display the name and age of those passengers.Given an aadhaar number, display the pickup location and destination location of that passenger. Input FormatFirst line represents the number of passengers, N.Subsequent lines represent passenger information (name, age, gender, aadhaar number, pickup location and destination location).Next line represents the pickup location for which the name and age of those passengers who board at that location have to be foundLast line represents the aadhaar number for whom the pickup location and destination location have to be found Sample Input:3Deepu29female123456789011chrompettrichyAnanya21female123567849010airportmaduraiVarun27male789456123074chrompetmaduraichrompet123567849010 Sample Output:male 1female 2Deepu 29Varun 27
Question
Luxury transport service offers luxurious travel facilities to passengers. At the time of ticket booking, the passengers have to give their details like name, age, gender, aadhaar number, pickup location and destination location. You are free to use any of the collection types to store passengers’ details. Write a user-defined function in python:To display the count of male and female passengers.To fetch the passenger details for a specific pickup location. If that location is not found, print “not found”. Else, display the name and age of those passengers.Given an aadhaar number, display the pickup location and destination location of that passenger. Input FormatFirst line represents the number of passengers, N.Subsequent lines represent passenger information (name, age, gender, aadhaar number, pickup location and destination location).Next line represents the pickup location for which the name and age of those passengers who board at that location have to be foundLast line represents the aadhaar number for whom the pickup location and destination location have to be found Sample Input:3Deepu29female123456789011chrompettrichyAnanya21female123567849010airportmaduraiVarun27male789456123074chrompetmaduraichrompet123567849010 Sample Output:male 1female 2Deepu 29Varun 27
Solution
Sure, I can help you with that. Here is a user-defined function in Python that fulfills the given requirements:
def passenger_details():
# Step 1: Get the number of passengers
num_passengers = int(input())
# Step 2: Create a dictionary to store passenger details
passengers = {}
# Step 3: Iterate over the number of passengers and collect their details
for _ in range(num_passengers):
name, age, gender, aadhaar, pickup, destination = input().split()
passengers[aadhaar] = {
'name': name,
'age': int(age),
'gender': gender,
'pickup': pickup,
'destination': destination
}
# Step 4: Count the number of male and female passengers
male_count = 0
female_count = 0
for passenger in passengers.values():
if passenger['gender'] == 'male':
male_count += 1
elif passenger['gender'] == 'female':
female_count += 1
# Step 5: Display the count of male and female passengers
print('male', male_count)
print('female', female_count)
# Step 6: Fetch passenger details for a specific pickup location
pickup_location = input()
found_passengers = []
for passenger in passengers.values():
if passenger['pickup'] == pickup_location:
found_passengers.append(passenger)
# Step 7: If pickup location is found, display name and age of passengers
if found_passengers:
for passenger in found_passengers:
print(passenger['name'], passenger['age'])
else:
print('not found')
# Step 8: Given an aadhaar number, display pickup and destination location
aadhaar_number = input()
if aadhaar_number in passengers:
passenger = passengers[aadhaar_number]
print(passenger['pickup'], passenger['destination'])
else:
print('not found')
# Call the function to execute the code
passenger_details()
Please note that this code assumes the input is provided in the specified format.
Similar Questions
Raju requires a program that prompts him to enter his name, ticket price, and travel destination. The program should then verify the availability of the chosen destination. If the destination is Delhi, the program should display a message indicating its unavailability. For all other destinations, the program should print Raju's details, including his name, ticket price, and destination.Input format :The first line of input consists of the string, representing the Passenger's name.The second line of input consists of a double, representing the ticket price.The third line of input consists of the string, and destination location.Output format :The output displays the following passenger information:Name: [Passenger's Name]Ticket Price: Rs. [Ticket Price]Destination Location: [Destination Location]If the destination is Delhi, print "Sorry, Delhi is not available as a destination".Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases will fall under the following constraintsThe input string with at most 49 characters.1000.00 ≤ ticket price ≤ 10000.00Sample test cases :Input 1 :Harpreet1200.50AmritsarOutput 1 :Passenger Information:Name: HarpreetTicket Price: Rs. 1200.50Destination Location: AmritsarInput 2 :Gurpreet1800.75DelhiOutput 2 :Sorry, Delhi is not available as a destination
Determine the proportion of passengers survived based on their passenger class.PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked01 0 3 Braund, Mr. Owen Harris Male 22 01 0 A/5 21171 7.2500 NaN S12 1 1 Cumings, Mrs.John Bradley Female 38 01 0 PC 17599 71.2833 C85 C23 1 3 Heikkinen, Miss. Laina Female 26 00 0 STON/O2. 3101282 7.9250 NaN S34 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) Female 35 01 0 113803 53.1000 C123 S45 0 3 Allen, Mr. William Henry Male 35 00 0 373450 8.0500 NaN SDetermine the proportion of passengers survived based on their passenger class.crosstab(df_train[‘Pclass’], df_train[‘Survived’])proportion(df_train[‘Pclass’], df_train[‘Survived’])crosstab(df_train[‘Survived’], df_train[‘Pclass’])None of these
What is one recommendation for providing transportation information in a travelogue?
In a busy airport, passengers are holding tickets with unique numbers. Write a program using the linear search algorithm to check if a given ticket number exists in the array of ticket numbers. If the ticket number is found, print a congratulatory message along with the position where it's found. If the ticket number is not found, encourage the passenger with a message for better luck on the next attempt.Input format :The first line of input consists of an integer N, representing the number of tickets.The second line consists of N space-separated integers, representing the ticket numbers.The third line consists of an integer, representing the ticket number to search.Output format :If the ticket number is found, print "Congratulations! Ticket number X found at position Y!", where X is the ticket number and Y is the position (position starts from 1).Otherwise, print "Better luck next time! Ticket number X not found!", where X is the ticket number.Refer to the sample output for formatting specifications.Code constraints :1 ≤ N ≤ 1010 ≤ ticket number ≤ 1000Sample test cases :Input 1 :5123 456 789 321 654321Output 1 :Congratulations! Ticket number 321 found at position 4!Input 2 :6741 456 982 364 789 258369Output 2 :Better luck next time! Ticket number 369 not found!Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Single File Programming QuestionProblem StatementIn a busy airport, passengers are holding tickets with unique numbers. Write a program using the linear search algorithm to check if a given ticket number exists in the array of ticket numbers. If the ticket number is found, print a congratulatory message along with the position where it's found. If the ticket number is not found, encourage the passenger with a message for better luck on the next attempt.Input format :The first line of input consists of an integer N, representing the number of tickets.The second line consists of N space-separated integers, representing the ticket numbers.The third line consists of an integer, representing the ticket number to search.Output format :If the ticket number is found, print "Congratulations! Ticket number X found at position Y!", where X is the ticket number and Y is the position (position starts from 1).Otherwise, print "Better luck next time! Ticket number X not found!", where X is the ticket number.Refer to the sample output for formatting specifications.Code constraints :1 ≤ N ≤ 1010 ≤ ticket number ≤ 1000Sample test cases :Input 1 :5123 456 789 321 654321Output 1 :Congratulations! Ticket number 321 found at position 4!Input 2 :6741 456 982 364 789 258369Output 2 :Better luck next time! Ticket number 369 not found!
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.