Python: simple version of subway station arrival principle, python station arrival

Source: Internet
Author: User
Tags add time

Python: simple version of subway station arrival principle, python station arrival
Python subway station arrival process and principle (my personal understanding)

Today, when I took the subway and looked at the station card, I wondered how it would work if I wrote it in Python.

Isn't it easy? I just want to try it out. Let's not try it out. It's just my personal understanding.

First, let's take a look at the following station signs displayed on the subway:

I just want to know the length of the site name with a fixed website name first. This is not in line with the list. [first station, second station,..., last station]

Put this write site name into the list, and a for Loop will automatically help you retrieve each site name. You can add time. sleep to set the time between each site,

When the time passes through the Yangtze river tunnel, you can add an if statement to determine whether the station name changes the default time. Here, you can also use the station name to determine whether the station name needs to be transferred and other self-brain extensions,

I wrote a simple version with so many complex functions that I did not add to write the most primitive line operation.

#! /Usr/bin/env python #-*-coding: UTF-8-*-import timeall_station = [u "Golden Beach", u "Evergreen Garden", u "Changgang road ", u "Hankou Railway Station", u "fan Hu", u "Wang jiadun East", u "Youth road", u "Zhongshan Park", u "Xu limen", u "Jianghan Road ", u "Ji yuqiao", u "crab ", u "turtle Hill", u "Hongshan Square", u "Central South Road", u "baotong Temple", u "Street exit ", u "", u "", u "yangjiawan", u "Guang Gu square",] light = [] for n in range (len (all_station): light. append (0) Count = 0for station in all_station: light [Count] = 1 print light if Count = 0: print u "Metro Line 2 departs from station ". format (station), print u "next station stop {}". format (all_station [Count + 1]) else: print u "{} has arrived ". format (station), if Count + 1 = len (all_station): print u "last station terminal {}". format (station) break time. sleep (3) print u "next station stop {}". format (all_station [Count + 1]) light [Count] = 0 time. sleep (3) Count + = 1

Import time module time

The benefit of using the list of all site names for all_station is that the extension line names can be expanded later.

Light indicates that the light below each site is displayed. Here, I simply use 0, 1 to judge which station is on When 0 indicates that the light is not on by default, and 1 indicates which station is on when the light is on.

The first for loop is to initialize all the lights, and the list is as good as the station expansion.

Next, the for loop reads the site name cyclically from all sites, which is equivalent to the subway arrival process.

Count is designed to indicate which station the light is displayed when counting is performed.

The final effect of the Code is as follows:

Because the screen is limited, only so many .....

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.