Train Management (Problem 17) - InfyTQ Solution in Python
Train Management (Problem 17)
InfyTQ Solution in Python
Photo by RAJAT JAIN from Pexels |
PROBLEM STATEMENT
The following are the details of trains:
Train No. | Train Name | From | To | Running Days | Sleeper Fair | AC Fair |
---|---|---|---|---|---|---|
16453 | Prasanti Express | SBC | BBS | 'Mo', 'We', 'Th' | 600 | 987 |
25627 | Karnataka Express | SBC | DEC | 'Su', 'Tu' | 1600 | 2500 |
22642 | Trivandrum SF Express | VSKP | TVM | 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa' | 800 | 1256 |
22905 | Okha Howrah Express | ST | KOAA | 'We', 'Sa' | 987 | 2879 |
Represent each train's detail as a dictionary in the following format:
train_dict={“train_no”:train number, “name”:train name, “from”:source, “to”:destination, “days_of_run”:list of running days, “sleeper_fare”:sleeper fare, “ac_fare”:AC fare }
Create a list of trains, name it as train_list. Consider it to be a global variable.
Refer the table below for the error messages to be returned for various conditions.
Function | Condition | Error essage |
---|---|---|
get_train_name (train_no) | If train number is not valid | “Invalid Train_no” |
get_trains_for_day (day_of_run) | If day is not in proper format | “Invalid day” |
- get_train_name(train_no)
This function accepts the train number and returns the dict which contains the details of the train. - get_trains_for_day(day_of_run)
This function accepts a day and returns the list of numbers of the trains running on that day. - get_total_fare(train_no,passenger_dict)
This function accepts train_no and a dictionary of passenger details. The passenger_dict is of the following format:
passenger_dict={ “sleeper”:5, “ac”,1 }
This function returns the total fare based on the passenger details and train number.
SOLUTION
SHARE
If you find this useful, please share with your friends and Community.
CODE TOGETHER..GROW TOGETHER.
CODE TOGETHER..GROW TOGETHER.
Newer Posts
Newer Posts
Older Posts
Older Posts
Comments