Professional Documents
Culture Documents
Mountain Train
Mountain Train
## Up train arrays
UpTrain = ["09:00","11:00","13:00","15:00"] ## train times for up train
UpMoney = [0,0,0,0] ## Total money for each up journey
UpPassengers = [0,0,0,0] ## Total passengers for each up journey
UpSeats = [480,480,480,480] ## Seats available for each up journey
def statistics():
global MaxJourney
global DirectionTravel
def TicketPurchase():
global UpJourney
global DownJourney
global NoPassengers
UpJourney = UpJourney - 1 ## Allows UpJourney to align with the
arrays, as the first item of arrays has a position of 0 and not 1
DownJourney = DownJourney - 1 ## same as above
while True:
try:
NoPassengers = int(input("\n> Groups of between 10 and 80
inclusive get a free ticket for every tenth passenger < \nInput number
of passengers: "))
if UpSeats[UpJourney] == (closed) or DownSeats[DownJourney] ==
(closed): ## train journeys with 0 seats available are changed to
CLOSED
print("Sorry, seats not available for chosen time(s). Refer to
train display.\n----")
choice()
break
if NoPassengers <= 0: ## user cannot purchase 0 tickets
print("Input value greater than 0.")
continue
if NoPassengers > UpSeats[UpJourney] or NoPassengers >
DownSeats[DownJourney]: ## checks if seats are available by comparing
input value with UpSeats/DownSeats array
print("Sorry, seats not available for chosen time(s). Refer to
train display.\n----")
choice()
break
verification()
break
except ValueError:
print(invalid)
def UpInput():
global UpJourney ## allows UpJourney variable to be used outside of
the function
while True:
try: ## try and except cancels input of the wrong data type,
allowing the program to not stop completely (ValueError)
UpJourney = int(input("\nWhich train journey UP the mountain - [
1, 2, 3, or 4 ] : "))
if UpJourney > 4 or UpJourney < 1: ## there are only train
journeys 1, 2, 3, and 4
print("Input train journey 1, 2, 3, or 4.")
continue
DownInput() ## calls DownInput function
break ## stops/breaks the while loop
except ValueError:
print(invalid)
def DownInput():
global DownJourney ## allows DownJourney variable to be used outside
of the function
while True:
try:
DownJourney = int(input("\nWhich train journey DOWN the mountain
- [ 1, 2, 3, or 4 ] : "))
if DownJourney > 4 or DownJourney < 1:
print("That is not a existing journey.")
continue
elif DownJourney < UpJourney:
print("This journey is not available as it is before your
journey up the mountain.") ## user cannot purchase a down time that is
before the up time.
continue ## goes back to the start of the While loop
TicketPurchase() ## calls TicketPurchase function
break
except ValueError:
print(invalid)
def choice():
while True:
Choice = input("\n----\n[ 1 ] to purchase tickets\n[ 2 ] to proceed
to end of day \nInput number based on your choice: ") ## gives user
choice of whether they want to purchase tickets or not
if Choice == ("1"):
UpInput() ## starts purchasing process by calling UpInput
function
break
elif Choice == ("2"):
statistics() ## Ends purchasing opportunity and displays the
statistics for the day by calling statistics function
break
else:
print("Input according to prompts above.")
continue
choice()