2016年8月31日水曜日

開発環境

Head First Python (Paul Barry (著)、 O'Reilly Media)のChapter 1.(the basics Getting Started Quickly)、Reviewing OUr Experiments の Code Experiments Magnets(No. 612) を取り組んでみる。

Code Experiments Magnets(No. 612)

コード(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().minute
    if right_this_minute in odds:
        print('This minuts 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 minuts seems a little odd.
This minuts seems a little odd.
Not an odd minute.
This minuts seems a little odd.
This minuts seems a little odd.
$

0 コメント:

コメントを投稿

Comments on Google+: