開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Python 3.5 (プログラミング言語)
Think Python (Allen B. Downey (著)、 O'Reilly Media)のChapter 5.(Conditionals and Recursion)のExercises 5-1(No. 1246)を取り組んでみる。
Exercises 5-1(No. 1246)
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
current_time = int(time.time())
sec_day = 24 * 60 * 60
days = current_time // sec_day
rest = current_time % sec_day
sec_hour = 60 * 60
hours = rest // sec_hour
rest = rest % sec_hour
sec_minute = 60
minutes = rest // sec_minute
rest = rest % sec_minute
secs = rest
print('hours: {0}, minutes: {1}, seconds: {2}, days since the epoch: {3}'.
format(hours, minutes, secs, days))
入出力結果(Terminal, IPython)
$ ./sample1.py hours: 9, minutes: 40, seconds: 13, days since the epoch: 16915 $
0 コメント:
コメントを投稿