by Nanzikambe · 12y ago · 0 comments
default_reasons = {
0: "leaves on the track",
1: "vandalism",
2: "drunk chavs",
3: "driver being absolutely shitfaced",
4: "solar flares",
5: "transport police randomly deciding to stop and search everyone on board",
6: "you having an interview",
7: "a possible UFO sighting in Belgium",
8: "British Rail",
9: "lack of coffee at the previous station, so the driver has just nipped off to get some",
10: "leaves on the track",
11: "flooding within 300km of a railway sleeper"
}
delay_all_trains_by_minutes = 5
if date.today().day % 2 == 1:
delay_all_trains_by_minutes = random.randrange(1,30,1)
print 'All trains will be delayed by %d minutes(s) due to %s' % \
(delay_all_trains_by_minutes, default_reasons[random.randrange(0,len(default_reasons),1)]) reasons = [
"leaves on the track",
"vandalism",
"drunk chavs",
"driver being absolutely shitfaced",
"solar flares",
"transport police randomly deciding to stop and search everyone on board",
"you having an interview",
"a possible UFO sighting in Belgium",
"British Rail",
"lack of coffee at the previous station, so the driver has just nipped off to get some",
"leaves on the track",
"flooding within 300km of a railway sleeper"
]
delay_all_trains_by_minutes = 5
if date.today().day % 2 == 1:
delay_all_trains_by_minutes = random.randint(0, 30)
print('All trains will be delayed by {} minute(s) due to {}'.format(
delay_all_trains_by_minutes, random.choice(reasons))default_reasons doesn't need to be a dict. Use a list.
You don't need random.randrange(). Use random.randint() to select a random integer and random.choice() to select a reason from default_reasons.
Fake edit: TY for the review :)
Edit: also I'd make it a tuple rather than either a dict or a list.
If nothing else, use lists because the syntax means it stays as a list even if you someday remove all but one option and forget to leave a comma, eg.
REASONS = [
'leaves on the line'
]
vs REASONS = (
'leaves on the line'
)12: "the late arrival of a preceding train",
13: "the train driver is currently en-route in a taxi" (I did not make this one up)
"arriving early at the previous station" & "a Swan on the line" & "a passenger refusing to leave the first class carriage, that only has a standard ticket" (police were called, delayed 25 mins)
"The 14.18 from Great Malvern is delayed due to leaves on the line. Unfortunately in this case the leaves were still attached to the tree."
Edit: O. M. G.
http://www.telegraph.co.uk/topics/weather/4434770/Snow-Brita...
Do you remember "the wrong kind of snow"? That was how
British Rail tried to explain away the complete
disruption of their services in London and the Southeast
on February 7 and 8, 1991.