为了账号安全,请及时绑定邮箱和手机立即绑定

Python 请帮忙看下原因:s = 23:56,D = 7,输出为23:03,为什么出错呀

Python 请帮忙看下原因:s = 23:56,D = 7,输出为23:03,为什么出错呀

慕用2276564 2018-06-21 10:34:04
s = input()D = int(input())for i in range(0, len(s)):   if s[i] == ':':      H = int(s[0 : i])      M = int(s[i+1 : len(s)])      if (M + D) >= 60 and (H + (M + D) // 60) < 24:         M = (M + D) % 60         H = H + (M + D) // 60      if (M + D) >= 60 and (H + (M + D) // 60) >= 24:         M = (M + D) % 60         H = (H + (M + D) // 60) % 24      if (M + D) < 60:         M = (M + D) % 60      if H < 10:         H = '0' + str(H)       if M < 10:         M = '0' + str(M)      print(str(H) + ':' + str(M))
查看完整描述

1 回答

?
慕用2276564

TA贡献4条经验 获得超1个赞

s = input()

D = int(input())

for i in range(0, len(s)):

   if s[i] == ':':

      H = int(s[0 : i])

      M = int(s[i+1 : len(s)])

      if (M + D) > 60 and (H + (M + D) // 60) < 24:

         H = H + (M + D) // 60

         M = (M + D) % 60

      elif (M + D) >= 60 and (H + (M + D) // 60) >= 24:

         H = (H + (M + D) // 60) % 24

         M = (M + D) % 60

      elif (M + D) < 60:

         M = (M + D) % 60

      if H < 10:

         H = '0' + str(H) 

      if M < 10:

         M = '0' + str(M)

      print(str(H) + ':' + str(M))

      break


查看完整回答
1 反对 回复 2018-06-21
  • 1 回答
  • 1 关注
  • 923 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信