|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
判断是否为闰年的那道题
我的程序这样写:
year=input('请输入一个年份,判断是否为闰年:')
while type(year,int)!=true:
print('输入不合法,')
year=input('请重新输入:')
a=year/400
b=year/4
c=year/100
print(year,end='')
if type(a,int)==true:
print('年是闰年')
else:
print('年是闰年')
if type(b,int)==true and type(c,int)!=true:
print('年是闰年')
else:
print('年不是闰年')
结果就是出错,参考答案用的事s.isdigit,判断是否全为数字,我用type()判断类型为什么就不可以啊
还有个问题时比如while和if后面的条件,如果只是判断真和假,像type这样出结果的,还有像我写的这样加一个判断语句么,直接while type(a,int),是真就继续执行?还是要这样while type(a,int)==true?
初学小甲鱼的课,问得太基础了,烦劳大神们不吝赐教
1,input接收的永远是字符串。
2,while type(a, int)就好。
|
|