開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
Head First Python (Paul Barry (著)、O'Reilly Media)のChapter 1.(The Basics: Getting Started Quickly)、Reviewing Our Experiments の Code Experiments Magnets(No. 1020) を取り組んでみる。
Code Experiments Magnets(No. 1020)
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import datetime
import random
import time
odds = list(filter(lambda n: n % 2 == 1, range(1, 60)))
for _ in range(5):
right_this_minute = datetime.datetime.today().minute
if right_this_minute in odds:
print('This minute seems a little odd.')
else:
print('Not an odd minute.')
wait_time = random.randrange(1, 61)
time.sleep(wait_time)
入出力結果(Terminal, IPython)
$ ./sample1.py This minute seems a little odd. Not an odd minute. Not an odd minute. This minute seems a little odd. Not an odd minute. $
0 コメント:
コメントを投稿