基於元組,根據月份,計算天數.(Python)

"""
    根據月份,計算天數.
"""

# month = int(input("請輸入月份:"))
# if month < 1 or month > 12:
#     print("輸入有誤")
# elif month == 2:
#     print("28天")
# # elif month == 4 or month == 6 or month == 9 or month == 11:
# elif month in (4,6,9,11):
#     print("30天")
# else:
#     print("31天")
month = int(input("請輸入月份:"))
if month < 1 or month > 12:
    print("輸入有誤")
else:
    # 將每月的天數,存入元組.
    day_of_month = (31,28,31,30,31,30,31,31,30,31,30,31)
    print(day_of_month[month - 1])

輸出:

請輸入月份:6
30

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