zoukankan      html  css  js  c++  java
  • py教程第5讲:解决闰年问题----input()的返回值始终是字符串

    temp = input('请输入年份:')

    while not isinstance(temp, int):
      temp = input('抱歉,您的输入有误,请输入年份:')

    year = int(temp)
    if year % 400 == 0:
      print('%d是闰年!'%(year))
    else:
    if year % 4 == 0 and year % 100 != 0:
      print('%d是闰年!' %(year))
    else:
      print('%d不是闰年!' %(year))

    所以更改后的代码如下(只修改while语句部分):

    while not temp.isdigit():
      temp = input('抱歉,您的输入有误,请输入年份:')

    Built-in Funtions BIF:内置函数

  • 相关阅读:
    基本排序
    mysql安装
    函数和方法
    COOKIE 与 SESSION
    django---入门
    django模板继承
    2017-11-14
    Django---模板层(template)
    Dajngo---model基础
    Django--基础篇
  • 原文地址:https://www.cnblogs.com/SWTwanzhu/p/6072947.html
Copyright © 2011-2022 走看看