Skip to content

Commit

Permalink
day 029 - traffic lights itertools
Browse files Browse the repository at this point in the history
  • Loading branch information
hobojoe1848 committed Apr 27, 2017
1 parent 6dc1093 commit dbc9e32
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions 029/traffic_lights.py
@@ -0,0 +1,28 @@
#!python3
#traffic light using itertools and random modules

from time import sleep
import itertools
import random

colours = 'Red Green Amber'.split()
rotation = itertools.cycle(colours)

def rg_timer():
return random.randint(5,9)

def light_rotation(rotation):
for colour in rotation:
if colour == 'Amber':
print('Caution! The light is %s.\n' % colour)
sleep(5)
elif colour == 'Red':
print('Stop! The light is %s.\n' % colour)
sleep(rg_timer())
else:
print('Go! The light is %s.\n' % colour)
sleep(rg_timer())


if __name__ == '__main__':
light_rotation(rotation)
2 changes: 1 addition & 1 deletion LOG.md
Expand Up @@ -30,7 +30,7 @@
| 026 | Apr 24, 2017 | [Simple script to retrieve #movie data from OMDb #API](026) | Get OMDB for movie data, query API by IMDB ID or title. Returns text or html. Uses request_cache to limit repeated calls to API. Could help some folks taking this [this week's challenge](http://pybit.es/codechallenge16.html) |
| 027 | Apr 25, 2017 | [rough script to query the #warcraft #API for a character's mounts](027) | A VERY rough and simple script to query the World of Warcraft API and pull the collected mounts of a specific character. Lots of room to expand this with stripping of JSON data and specifying which data to pull. Just some fun with a new and unconmmon API! |
| 028 | Apr 26, 2017 | [Jupyter notebook to plot and list new #Python titles on @safari by month](028) | Learning: parsing a Twitter CSV backup dump (@newsafaribooks account), matplotlib, collections, hacking iPython css |
| 029 | Apr 27, 2017 | [TITLE](029) | LEARNING |
| 029 | Apr 27, 2017 | [Traffic Lights script to demo #itertools cycle](029) | A nice and easy script to simulate traffic lights using `itertools.cycle` and other stdlib modules cycle. Itertools rocks! |
| 030 | Apr 28, 2017 | [TITLE](030) | LEARNING |
| 031 | Apr 29, 2017 | [TITLE](031) | LEARNING |
| 032 | Apr 30, 2017 | [TITLE](032) | LEARNING |
Expand Down

0 comments on commit dbc9e32

Please sign in to comment.