@WiNDfaLLx/

0478/21: Pre-release Code (candidate 4504, centre 10172)

Python

0478/21: Pre-release Code (candidate 4504, centre 10172)

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#(c) Trisha Mukherjee aka 4504. All code is 100% thought out & written by me

allBusData = [  #dimension 1: 6 arrays, one per bus bus
    ["A",       #dimension 2: bus label and 4 arrays, one per week
    [],[],[],[] #dimension 3: 5 integers to be appended to
    ],          #             each array (one per day)

    ["B",
    [],[],[],[]
    ],

    ["C",
    [],[],[],[]
    ],

    ["D",
    [],[],[],[]
    ],
    
    ["E",
    [],[],[],[]
    ],
    
    ["F",
    [],[],[],[]
    ]
]

"""allBusData = [["A",[0,0,0,2,2],[4,0,3,4,-2],[-5,0,0,3,4],[-1,8,1,1,-2]],["B",[0,1,0,0,1],[2,0,0,0,0],[1,0,0,0,2],[0,0,1,0,0]]]
#sample data"""

days = ("Mon", "Tue", "Wed", "Thu", "Fri") #tuple: a 'constant array'

data = "" #simple 'placeholder' variable for validation checks

lateDayCounter = 0
lateDayTotaller = 0
latestBusCount = 0
latestBusName = ""

#task 1

for bus in allBusData:
    print("Entering data for Bus", bus[0])
    for week in range(1, 5): #loops through 1, 2, 3 and 4 (excludes 5)
        print("Entering data for Week", week)
        for day in days:
            data = input("Enter data for " + day + str(week) + ": ")
            while not (data.isdigit() \
            or (data[1:].isdigit() and data[0] == "-")):
                #.isdigit() rejects negative numbers; this includes them
                data = input("Invalid data. Please enter an integer (may be negative): ")
            bus[week].append(int(data))

#task 2

print("\nNumber of late arrivals for each bus bus:")

for bus in allBusData:
    lateDayCounter = 0
    for week in range(1, 5):
        for day in bus[week]:
            if day < 0:
                lateDayCounter += 1
    print(lateDayCounter, "late arrivals for Bus", bus[0])

print("\nAverage number of minutes late for each bus bus:")

for bus in allBusData:
    lateDayTotaller = 0
    for week in range(1, 5):
        for day in bus[week]:
            lateDayTotaller += day
    lateDayTotaller = lateDayTotaller / 20
    if lateDayTotaller < 0:
        print((lateDayTotaller * -1), "minutes late for Bus", bus[0])
    else:
        print(lateDayTotaller, "minutes early for Bus", bus[0])

for bus in allBusData:
    lateDayCounter = 0
    for week in range(1, 5):
        for day in bus[week]:
            if day < 0:
                lateDayCounter += 1
    if lateDayCounter > latestBusCount:
        latestBusCount = lateDayCounter
        latestBusName = bus[0]

print("\nBus bus with highest number of days it was late:", latestBusName)

print("\nAverage number of minutes late for each bus bus, using only data from days on which it was late:")

for bus in allBusData:
    lateDayCounter = 0
    lateDayTotaller = 0
    for week in range(1, 5):
        for day in bus[week]:
            if day < 0:
                lateDayCounter += 1
                lateDayTotaller -= day
    if lateDayCounter == 0:
        print("Bus", bus[0], "was never late")
    else:
        print(round(lateDayTotaller/lateDayCounter, 1), "minutes late on late days for Bus", bus[0])

#task 3

data = input("Input the day you are checking: ")

while data[0:3] not in days or data[3:] not in ["1", "2", "3", "4"]:
    data = input("Invalid data. Enter a proper day code: ")

checkedDay = days.index(data[0:3])
checkedWeek = int(data[3])

lateDayCounter = 0

for bus in allBusData:
    if bus[checkedWeek][checkedDay] < 0:
        lateDayCounter += 1
print("\nNumber of buses that were late on this particular day:", lateDayCounter)

for bus in allBusData:
    if bus[checkedWeek][checkedDay] < 0:
        print("Bus", bus[0], "was", \
        (bus[checkedWeek][checkedDay]*-1), "minutes late on this particular day")

#end