開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
初めてのコンピュータサイエンス(Jennifer Campbell、Paul Gries、Jason Montojo、Greg Wilson(著)長尾 高弘(翻訳))の4章(モジュール)、4.8(練習問題)、1、2を解いてみる。
4.8(練習問題)、1、2.
コード(BBEdit)
sample.py
#!/usr/bin/env python3.4
#-*- coding: utf-8
import math
print('1.')
for x in [abs(round(-4.3)), math.ceil(math.sin(34.5))]:
print(x)
print('2.')
import calendar
import datetime
year = datetime.date.today().year
while not calendar.isleap(year):
year += 1
print('次のうるう年: {0}年'.format(year))
leapdays = calendar.leapdays(2000, 2051)
print('2000年から2050年までの間にあるうるう年の回数: {0}回'.format(leapdays))
weekday = calendar.weekday(2016, 7, 29)
print('2016/7/29 weekday: {}'.format(calendar.day_name[weekday]))
入出力結果(Terminal)
$ ./sample.py 1. 4 1 2. 次のうるう年: 2016年 2000年から2050年までの間にあるうるう年の回数: 13回 2016/7/29 weekday: Friday $
0 コメント:
コメントを投稿