In: Computer Science
This Homework would have two python files for a cheap online ticket seller. (You are free to imagine a new scenario and change any part of the question.)
The main purpose of the homework is to use basic concepts. You should try to use basic python elements like variables, if-else, loops, lists, dictionary, tuple, functions in this homework.
***
Price list to calculate the price for various destinations---
Price For Delta $ 200.00 (Economy), 300.00(Business), 400(First class)
United 220.00 (Economy), 330.00(Business), 410(First class)
Lufthansa 250.00(Economy), 340.00(Business), 410(First class)
American 260.00(Economy), 300.00(Business), 420(First class)
Price for Delta $ 250.00(Economy), 300.00(Business), 400(First class)
United $270.00 (Economy), 300.00(Business), 400(First class)
Lufthansa $ 290.00, (Economy), 300.00(Business), 400(First class)
American $ 280.00(Economy), 300.00(Business), 400(First class)
Price for Delta $ 350.00(Economy), 410.00(Business), 500.00(First class),
United 360.00(Economy), 4200.00(Business), 510(First class),
Lufthansa 370.00(Economy), 440.00(Business), 530(First class),
American 370.00(Economy), 430.00(Business), 510(First class)
Price For Delta $ 370.00(Economy), 410.00(Business), 520(First class),
United 380.00(Economy), 430.00(Business), 550(First class),
Lufthansa 390.00(Economy), 460.00(Business), 600.00(First class),
American 400.00(Economy), 470.00(Business), 590.00(First class)
For 6.00 AM and 11.00 AM flight, nothing to extra charge but 2.00 PM and & 7.00 flight has a $ 50.00 extra charge to book. However, the 11.00 PM flight has an extra charge of $ 70
***
Output: Do you Want to buy a ticket?
Enter Option 1 for buy ticket 2 for no:
How many people are you going to travel with? (Choose option Maximum 5):
Choose your destination from the below options menu:
What airline company do you want to travel with for destination:
Choose an option from the menu:
What class do you want to travel to? :
Choose an option from the menu:
What time would you like to travel to a destination? :
Choose an option from the menu:
The total price for your travel ticket is:
Enter Option 1 for buy ticket 2 for no:
Refer screenshots for correct indentation,without correct indetation programm may show errors/work incorrectly, also make sure that both files are in same folder
utilities.py
# hold ticket classes
TICKET_CLASSES = ('ECONOMY', 'BUSINESS CLASS', 'FIRST CLASS')
# holds destinations
DESTINATIONS = ('NEW YORK','LAS ANGELES', 'CLEVELAND', 'DALLAS','LAS VEGAS')
# holds airline names
AIRLINES = ('DELTA', 'UNITED', 'LUFTHANSA', 'AMERICAN')
# holds times
TIME = ('06.00 AM', '11.00 AM', '02.00 PM', '07.00 PM', '11.00 PM')
# holds the prices
PRICE_TABLE = {
DESTINATIONS[0]:{
AIRLINES[0]:{TICKET_CLASSES[0]:200.00, TICKET_CLASSES[1]:300.00, TICKET_CLASSES[2]:400},
AIRLINES[1]:{TICKET_CLASSES[0]:220.00, TICKET_CLASSES[1]:330.00, TICKET_CLASSES[2]:410},
AIRLINES[2]:{TICKET_CLASSES[0]:250.00, TICKET_CLASSES[1]:340.00, TICKET_CLASSES[2]:410},
AIRLINES[3]:{TICKET_CLASSES[0]:260.00, TICKET_CLASSES[1]:300.00, TICKET_CLASSES[2]:420}
},
DESTINATIONS[1]:{
AIRLINES[0]:{TICKET_CLASSES[0]:250.00, TICKET_CLASSES[1]:300.00, TICKET_CLASSES[2]:400},
AIRLINES[1]:{TICKET_CLASSES[0]:270.00, TICKET_CLASSES[1]:300.00, TICKET_CLASSES[2]:400},
AIRLINES[2]:{TICKET_CLASSES[0]:290.00, TICKET_CLASSES[1]:300.00, TICKET_CLASSES[2]:400},
AIRLINES[3]:{TICKET_CLASSES[0]:280.00, TICKET_CLASSES[1]:300.00, TICKET_CLASSES[2]:400}
},
DESTINATIONS[2]:{
AIRLINES[0]:{TICKET_CLASSES[0]:350.00, TICKET_CLASSES[1]:410.00, TICKET_CLASSES[2]:500},
AIRLINES[1]:{TICKET_CLASSES[0]:360.00, TICKET_CLASSES[1]:420.00, TICKET_CLASSES[2]:510},
AIRLINES[2]:{TICKET_CLASSES[0]:370.00, TICKET_CLASSES[1]:440.00, TICKET_CLASSES[2]:530},
AIRLINES[3]:{TICKET_CLASSES[0]:3700.00, TICKET_CLASSES[1]:430.00, TICKET_CLASSES[2]:510}
},
DESTINATIONS[3]:{
AIRLINES[0]:{TICKET_CLASSES[0]:200.00, TICKET_CLASSES[1]:300.00, TICKET_CLASSES[2]:400},
AIRLINES[1]:{TICKET_CLASSES[0]:220.00, TICKET_CLASSES[1]:330.00, TICKET_CLASSES[2]:410},
AIRLINES[2]:{TICKET_CLASSES[0]:250.00, TICKET_CLASSES[1]:340.00, TICKET_CLASSES[2]:410},
AIRLINES[3]:{TICKET_CLASSES[0]:260.00, TICKET_CLASSES[1]:300.00, TICKET_CLASSES[2]:420}
},
DESTINATIONS[4]:{
AIRLINES[0]:{TICKET_CLASSES[0]:370.00, TICKET_CLASSES[1]:410.00, TICKET_CLASSES[2]:520},
AIRLINES[1]:{TICKET_CLASSES[0]:380.00, TICKET_CLASSES[1]:430.00, TICKET_CLASSES[2]:550},
AIRLINES[2]:{TICKET_CLASSES[0]:390.00, TICKET_CLASSES[1]:460.00, TICKET_CLASSES[2]:600},
AIRLINES[3]:{TICKET_CLASSES[0]:400.00, TICKET_CLASSES[1]:470.00, TICKET_CLASSES[2]:590}
}
}
# for getting extracharge if any
def getExtraCharge(time):
if time in [TIME[0], TIME[1]]:
return 0
elif time in [TIME[2], TIME[3]]:
return 50.00
elif time in[TIME[4]]:
return 70.00
# calculates the price
def calculatePrice(people, destination, airline, ticketClass, time):
return people * (PRICE_TABLE[DESTINATIONS[destination-1]][AIRLINES[airline-1]][TICKET_CLASSES[ticketClass-1]] + getExtraCharge(TIME[time-1]))
screenshot:
application.py
import utilities
def main():
# checks if user wants to buy
print('Do you Want to buy a ticket?')
option = input('Enter Option 1 for buy ticket 2 for no: ')
# if yes then continue
if option == '1':
# reads passenger count
print('''
Options
--------
1) One passenger
2) Two passengers
3) Three passengers
4) Four passengers
5) Five passengers
''')
people = int(input('How many people are you going to travel with? (Choose option 1-5): '))
# reads destination
print('''
Options
--------
1) NEW YORK
2) LAS ANGELES
3) CLEVELAND
4) DALLAS
5) LAS VEGAS
''')
destination = int(input('Choose your destination from the options menu(1-5): '))
# reads airline name
print('''
Options
--------
1) DELTA
2) UNITED
3) LUFTHANSA
4) AMERICAN
''')
airline = int(input('What airline company do you want to travel with for destination:\nChoose an option from the menu(1-4):'))
# reads ticket class
print('''
Options
--------
1) FIRST CLASS
2) BUSINESS CLASS
3) ECONOMY
''')
ticketClass = int(input('What class do you want to travel to? :\nChoose an option from the menu(1-3):'))
# reads time
print('''
Options
--------
1) 06.00 AM
2) 11.00 AM
3) 02.00 PM
4) 07.00 PM
5) 11.00 PM
''')
time = int(input('What time would you like to travel to a destination? :\nChoose an option from the menu(1-5):'))
# prints the price
print('The total price for your travel ticket is: ', utilities.calculatePrice(people, destination, airline, ticketClass, time),'$')
# confirm if user wants to buys
buy = input('Enter Option 1 for buy ticket 2 for no: ')
if buy == '1':
print('Thank You for flying with us, Have a Nice Day!')
else:
print('Thank You Have a Nice Day!')
# running main if it run as a script
if __name__ == '__main__':
main()
screenshot:
output:
PS: If you have any problems/doubts please comment below.Thank You.