我正在编写一个Python脚本,用于“输入秒数”并以周、天、小时、分钟和秒为单位获取结果。这是我的代码,但我没有得到正确的答案。我做错了什么?
seconds = raw_input("Enter the number of seconds:")
seconds = int(seconds)
minutes = seconds/60
seconds = seconds % 60
hours = minutes/60
hours = seconds/3600
minutes = minutes % 60
days = hours/24
days = minutes/1440
days = seconds/86400
hours = hours % 60
hours = minutes % 60
hours = seconds % 3600
weeks = days/7
weeks = hours/168
weeks = minutes/10080
weeks = seconds/604800
days = days % 1
days = hours % 24
days = minutes % 1440
days = seconds % 86400
weeks = weeks % 1
weeks = days % 7
weeks = hours % 168
weeks = minutes % 10080
weeks = seconds % 604800
print weeks, 'weeks', days, 'days', hours, 'hours', minutes, 'minutes', seconds, 'seconds'
divmod
函数将一次性返回商和余数。 - Keith