I want the arrays to be updated when the loop repeats
like the new values for the user as tickets have been subtracted.
some details
i need them to be for the new user that uses the interfaces the interface ,
while True:
import time
#task1
uptime=[9,11,13,15]
uptickets=[480,480,480,480]
upmoney=[0,0,0,0]
downtime=[10,12,14,16]
downtickets=[480,480,480,640]
downmoney=[0,0,0,0]
print("Welcome")
print("Times for going up are:",uptime)
print("Times for going down are",downtime)
x=0
print ("Tickets remaining per time are=")
for x in range (0,4):
print (uptime[x], uptickets[x])
print (downtime[x], downtickets[x])
#task 2
Userup=int(input("Enter time for going up "))
while Userup !=9 and Userup !=11 and Userup !=13 and Userup !=15:
print("invalid")
Userup=int(input("Enter time for going up "))
Userdown=int(input("Enter time for going down "))
while (Userdown !=10 and Userdown!=12 and Userdown!=14 and Userdown !=16) or
Userdown < Userup:
print("invalid")
Userdown=int(input("Enter time for going down "))
#extracting indexes
for count in range(0,4):
if Userup==uptime[count]:
upindex=count
#print(upindex)
for count in range(0,4):
if Userdown==downtime[count]:
downindex=count
#print(downindex)
time.sleep(2)
#input tickets
num_tickets=int(input("Enter number of tickets "))
while num_tickets > uptickets[upindex] and num_tickets > downtickets[downindex]:
print("Error. Check availability: Enter number of tickets again")
num_tickets=int(input("Enter number of tickets "))
#cost calculation
one_cost=25
trip_cost=one_cost*(num_tickets-int(num_tickets/10))
print("cost is",trip_cost)
print("2 way cost is",trip_cost*2)
time.sleep(2)
#updated display
uptickets[upindex]=uptickets[upindex]-num_tickets
downtickets[downindex]=downtickets[downindex]-num_tickets
upmoney[upindex] = upmoney[upindex] + trip_cost
downmoney [downindex] = downmoney [downindex] + trip_cost
for x in range (0,4):
if uptickets [x] == 0:
uptickets [x] = str (uptickets[x])
uptickets [x] = "Closed"
if downtickets [x] == 0:
downtickets [x] = str (downtickets[x])
downtickets [x] = "Closed"
time.sleep(2)
print ("Tickets remaining per time are=")
time.sleep(0.5)
for x in range (0,4):
print (uptime[x], uptickets[x], upmoney[x])
print (downtime[x], downtickets[x], downmoney[x])
#task3
totalpassengers=0
totalmoney=0
up_passenger=[0,0,0,0]
down_passenger=[0,0,0,0]
for x in range(0,3):
up_passenger[x]=480-uptickets[x]
print("For time:",uptime[x],"there are",up_passenger[x],"passengers")
totalpassengers = totalpassengers + up_passenger[x]
up_passenger[3]=480-uptickets[3]
print("For time:",uptime[3],"there are",up_passenger[3],"passengers")
totalpassengers = totalpassengers + up_passenger[3]
for x in range(0,3):
down_passenger[x]=480-downtickets[x]
print("For time:",downtime[x],"there are",down_passenger[x],"passengers")
totalpassengers = totalpassengers + down_passenger[x]
down_passenger[3]=640-downtickets[3]
print("For time:",downtime[3],"there are",down_passenger[3],"passengers")
totalpassengers = totalpassengers + down_passenger[3]
totalpassengers/=2
totalpassengers=int(totalpassengers)
print ("Total passengers today:", totalpassengers)
for x in range (0,4):
totalmoney = totalmoney + upmoney[x]
totalmoney = totalmoney + downmoney[x]
print ("Total Money taken is:", totalmoney)
I want the arrays to be updated when the loop repeats
like the new values for the user as tickets have been subtracted.
some details
i need them to be for the new user that uses the interfaces the interface ,
question from:
https://stackoverflow.com/questions/66059945/arrays-dont-get-updated-in-a-while-loop