The arrival process and principle of the Python Metro (personal Understanding)
Today, taking the subway to look at the bus stop is inexplicable, if you write how it works in Python
is not very simple to try sledgehammer the next big boys do not spray purely brother personal understanding
First, take a look at the following signs on the subway:
Just want this first site fixed name fixed site name length can know, this is not a match list well [first station, second station, ... , Last stop]
Put this station name into the list A For loop automatically takes each station name you can add Time.sleep to set the time between each station,
The time of the Yangtze River Tunnel can be added individually if the station name change the default time, here can also be determined by the station name if you need to transfer and other self-brain expansion, etc.
Well, that's all I've done. I've written a simple version that doesn't add so many complicated functions to write the most primitive line.
#!/usr/bin/env python#-*-coding:utf-8-*-Importtimeall_station=[u"Gold and Silver Beach", u"Evergreen Garden", u"Long Kong Road", u"Hankou railway station", u"fan Hu", u"Wang Jia Dun dong", U"Youth Road", u"Zhongshan Park", u"Xu Li door", u"Jianghan Road", u"Jiyuqiao", U"Crab Cape", u"Little Tortoise", u"Hongshan Plaza", u"Zhongnan Road", u"Po Thong Temple", U"Street Mouth", u"Guang Bu Tun", u"Tiger Spring", u"Yang Jia Wan", u"Optics Valley Square",]light= [] forNinchRange (len (all_station)): Light.append (0) Count=0 forStationinchAll_station:light[count]=1Print Lightifcount==0:PrintU"Metro line Line 2 departs from {} Station". Format (station),PrintU"Next station next stop {}". Format (All_station[count + 1]) Else: PrintU"{} is on the arrival". Format (station),ifcount+1==Len (all_station):PrintU"Last station Terminal {}". Format (station) BreakTime.sleep (3) PrintU"Next station next stop {}". Format (All_station[count + 1]) Light[count]=0 Time.sleep (3) Count+=1
Import Time Module
All_station List of all station names there is also the advantage that later extensions can extend the line name
Light indicates that each site below the display here I simply use 0,1 to Judge 0 means the default is not lit, 1 indicates to which station lights
The first for loop is to initialize all the lights as well as list lists as good as the station expands
The next for loop is to cycle through all sites to read the station name equivalent to the subway arrival process
Count is designed to represent the count at the same time to show which station the light is lit
Let's look at the final effect of the code as follows:
Because the screen is limited only so much .....
Python writes the schematic of the subway's arrival in a simple version