从控制台输入一个时间,打印这个时间的下一秒[16:33:55]
[23:59:59] 显示[00:00:00]
reminder = (input("请输入时间:[H:M:S]"))
while True:
time = reminder.split(':')
hour = int(time[0])
minute = int(time[1])
second = int(time[-1])
# 判断输入的时间是否符合格式,,三次机会
for i in range(1, 4):
if hour > 23 or minute > 59 or second > 59:
twice = input("请输入正确的时间格式:")
# 输入一次,次数+1
i += 1
time = twice.split(':')
# 获取字符串的hour部分
hour = int(time[0])
# 获取minute部分
minute = int(time[1])
# 获取second部分
second = int(time[-1])
if hour <= 23 and minute <= 59 and second <= 59:
second += 1
if second != 60:
# 使用.format进行输出,当然格式化字符串也可以
print("当前时间为{}:{}:{}".format(hour, minute, second))
else:
second = '00'
minute += 1
if minute != 60:
print("当前时间为{}:{}:{}".format(hour, minute, second))
else:
minute = '00'
hour += 1
if hour == 24:
print("当前时间为{}".format('00:00:00'))
else:
print("当前时间为{}:{}:{}".format(hour, minute, second))
else:
print("你在逗我吗?输错3次了,拜拜!你没机会玩了")
break
# 输入正确的时间,则执行以下步骤
if hour <= 23 and minute <= 59 and second <= 59:
second += 1
if second != 60:
print("当前时间为{}:{}:{}".format(hour,minute,second))
else:
second = '00'
minute += 1
if minute != 60:
print("当前时间为{}:{}:{}".format(hour, minute, second))
else:
minute = '00'
hour += 1
if hour == 24:
print("当前时间为{}".format('00:00:00'))
else:
print("当前时间为{}:{}:{}".format(hour, minute, second))
break