Python writes the schematic of the subway's arrival in a simple version

Source: Internet
Author: User
Tags add time

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.