-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq5_b.py
27 lines (22 loc) · 860 Bytes
/
q5_b.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
import q5_a
def number_of_winners(qualifying_time, race_results):
""" (str, file open for reading) -> int
A valid time is a str with format 'h:m:s', with 0 <= int(h) <= 23,
0 <= int(m) <= 59 and 0 <= int(s) <= 59.
Precondition: qualifying_time is a valid time,
Each line in race_results contains a single valid time.
Return the number of lines in race_results that contain a time that is
below qualifying_time.
"""
x = q5_a.convert_time_to_seconds(qualifying_time)
#累加
winners = 0
for line in race_results:
y = q5_a.convert_time_to_seconds(line.strip())
if y < x:
winners = winners + 1
return winners
if __name__ == '__main__':
twm = open('twm_times.txt', 'r')
print('Number of prize winners:', number_of_winners('3:20:14', twm))
twm.close()