The first task here is to decide how to store the data from the table in figure 2 that has the details of aircraft in. - It may be sensible to store them as another list of lists perhaps ?
However, there are only three types of aircraft so you may decide to just test the inputs against each string in turn
If type == "medium wide body" etc.
If I decide to make another list with this data in - I am calling it planes[ ]
Then It may make sense to use another text file like last time to do that - You can make a text file out of the data above in notepad. (This means I can re-use my code for loading and splitting up the file)
I have made the above text file and called it planes.txt - I put it in the same location (folder / directory) as my program - if you are in repl then it needs to be uploaded again like the other file.
Then I can use most of the code I already wrote to put the data into a list of lists called planes
The definition below will load the new text file and then use the same definition called splitLines that I used on the other text file to put the data into a list of lists called planes.
I have just copied the code from my previous file opening and changed the text file name. - If I wanted to be even more clever I could have amended the text file opening code to ask for a filename thus making it work with any text file formatted as CSV. - This would be useful if the program was to deal with different aircraft fleets in the future.
The next bit is to check on the aircraft type - see below for how I approached it
The code above all follows on - so the above is just one definition even though it is in two pictures -( could not fit all into one snip easily)
When this bit is complete - i.e. when there is a correct aircraft type selected we need to get some more info about that aircraft - I decided to store this info into some Global variables again - although you could use a new tuple or list for this as well.
I will need (later) the:
- running cost of the selected aircraft type
- Minimum First Class seats for the selected aircraft
- Range of the aircraft
- Maximum capacity of the aircraft
The code below is how I went about doing this - gaining the info and storing in globals - now I am not too happy with using so many globals but it does make life easier later perhaps
The code above uses two other functions I have written
EnterFirstClass and CalcStandardSeats
the above takes two parameters allstandard and firstclass computes the standard seats and returns that value.
The above also takes two parameters the minSeats and the allStandard
It returns the number of first class seats.
The error checking is inside this code - it returns to the menu if there is an error in the number of seats entered