栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python:输入一个年份,判断是否为闰年

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python:输入一个年份,判断是否为闰年

#输入一个年份,判断是否为闰年
message_1 = "Enter a number to judge if it is a leap year: "
message_2 = " is a leap year."
message_3 = " is not a leap year."
message_4 = "continue or quit? "
message_5 = "Wrong, please enter 'continue' or 'quit'. "

choice = True
while choice == True:
     year = input(message_1)  #输入年份
     year_1 = int(year)       #字符串转换为数字
     if year_1%400 == 0:      #判断是否为闰年
          print(year+message_2)
     elif year_1%100 == 0:
          print(year+message_3)
     elif year_1%4 ==0:
          print(year+message_2)
     else:
          print(year+message_3)
     choice_1 = input(message_4)
     while choice_1 != "continue" and choice_1 != "quit":      #防止输入错误
          choice_1 = input(message_5)
     if choice_1 == "quit":        #结束循环
          choice = False

        用Python编写的第一个比较有意义的小程序。选择这个程序是因为大一上学期计算思维课学习C语言的时候也用C语言编写过这样一个程序,印象深刻。

        以后会多编写一些有趣的小程序~~~

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/757612.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号