Python 初體驗之一—HelloWorld

“Hello World”非常非常著名,但凡是編程語言,第一課都要玩這個例程,下面我們也看一看Python 的


Hello World 示例

練習

1.計算今年是閏年嘛?判斷閏年條件, 滿足年份模400爲0, 或者模4爲0但模100不爲0.

#coding:utf-8
'''cdays-5-exercise-1.py 判斷今年是否是閏年
    @note: 使用了import, time模塊, 邏輯分支, 字串格式化等
'''

import time                             #導入time模塊
thisyear = time.localtime()[0]             #獲取當前年份
if thisyear % 400 == 0 or thisyear % 4 ==0 and thisyear % 100 <> 0: #判斷閏年條件, 滿足模400爲0, 或者模4爲0但模100不爲0
    print 'this year %s is a leap year' % thisyear
else:
    print 'this year %s is not a leap year' % thisyear


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章