2018年7月22日日曜日

開発環境

Head First Python (Paul Barry (著)、O'Reilly Media)のChapter 1.(The Basics: Getting Started Quickly)、CODE EXPERIMENTS MAGNETS(No. 1021)を取り組んでみる。

コード(Emacs)

Python 3

#!/usr/bin/env python3
from datetime import datetime
import time
import random

odds = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29,
        31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 15, 53, 55, 57, 59]

for _ in range(5):
    right_this_minute = datetime.today().minute
    if right_this_minute in odds:
        print('This minute seems a little odd.')
    else:
        print('Not an odd minute.')
    waite_time = random.randrange(1, 61)
    time.sleep(waite_time)

入出力結果(Terminal, Jupyter(IPython))

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

0 コメント:

コメントを投稿