2017年1月16日月曜日

開発環境

Head First Python (Paul Barry (著)、O'Reilly Media)のChapter 1.(The Basics: Getting Started Quickly)、Reviewing Our Experiments の Code Experiments Magnets(No. 1004) を取り組んでみる。

Code Experiments Magnets(No. 1004)

コード(Emacs)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import datetime
import random
import time

odds = range(1, 60, 2)

for _ in range(5):
    right_this_minute = datetime.datetime.today().second
    if right_this_minute in odds:
        print('This minute seems a little odd.')
    else:
        print('Not an odd minute.')

    wait_time = random.randrange(1, 10)
    time.sleep(wait_time)

入出力結果(Terminal, IPython)

$ ./sample1.py
This minute seems a little odd.
This minute seems a little odd.
Not an odd minute.
This minute seems a little odd.
This minute seems a little odd.
$

0 コメント:

コメントを投稿