西瓜板栗 发表于 2020-3-21 02:49:40

零基础的第五课!

我这个程序是哪里出问题了{:10_266:} {:10_266:} 怎么都看不出来,求求大佬们教教我



print('输入一个年份 我来判断是否是闰年!')
temp = input()
year = int(temp)
tiaojianone = (year/400)
#能被400整除都是闰年
tiaojiantwo = (year/4)
tiaojianthree = (year/100)
#能被4整除但不能被100整除是闰年

if type((tiaojiansan) != type(1)) and type((tiaojiantwo) == type(1)):
    print('这是闰年哦')
else:
    if type(tiaojianthree) == type(1):
      print('这是闰年哦')
    else:
      print('这不是闰年')

Judie 发表于 2020-3-21 06:29:28

if type((tiaojianthree) != type(1)) and type((tiaojiantwo) == type(1)):
这里括弧括错了!!!

>>> type(True)
<class 'bool'>
>>> type(False)
<class 'bool'>
您瞧 True 和 False 都是 bool
所以 总是不过else
直接你的第一个print语句 这是闰年哦

正解
print('输入一个年份 我来判断是否是闰年!')
temp = input()
year = int(temp)
tiaojianone = (year/400)
#能被400整除都是闰年
tiaojiantwo = (year/4)
tiaojianthree = (year/100)
#能被4整除但不能被100整除是闰年

if (type(tiaojianthree) != type(1)) and (type(tiaojiantwo) == type(1)):
    print('这是闰年哦')
else:
    if type(tiaojianone) == type(1):
      print('这是闰年哦')
    else:
      print('这不是闰年')


看在我这么努力帮你找bug的份上
能求个【最佳答案】嘛
谢谢您!{:10_256:}

Judie 发表于 2020-3-21 06:30:43

哈哈哈哈 又是你!{:10_256:}

西瓜板栗 发表于 2020-3-21 18:59:34

Judie 发表于 2020-3-21 06:30
哈哈哈哈 又是你!

啊 好丢人 {:10_266:}{:10_266:}

Judie 发表于 2020-3-21 23:43:06

西瓜板栗 发表于 2020-3-21 05:59
啊 好丢人

不丢人不丢人 丢人的是我 蜜汁尴尬 {:10_266:}

啊哦哦啊 不好意思 还有一个bug

就算是整除了 也还是float 绝了

>>> 2/2
1.0
>>> type(2/2)
<class 'float'>


正解 妥妥的正解

print('输入一个年份 我来判断是否是闰年!')
temp = input()
year = int(temp)
tiaojianone = (year/400)
#能被400整除都是闰年
tiaojiantwo = (year/4)
tiaojianthree = (year/100)
#能被4整除但不能被100整除是闰年

if ((tiaojianthree) != int(tiaojianthree)) and ((tiaojiantwo) == int(tiaojiantwo)):
    print('这是闰年哦')
else:
    if (tiaojianone) == int(tiaojianone):
      print('这是闰年哦')
    else:
      print('这不是闰年')


页: [1]
查看完整版本: 零基础的第五课!