我是python的新手。我在v3.3工作。我正在尝试输入秒数并将其分解为天,小时,分钟和秒。如果小时为0或秒为0,我也需要不打印。问题是我似乎根本没有计算秒数。我输入97765秒当我运行它没有if else秒时它给了我一个0这是错误的如果我保留if else它不会打印任何错误的东西。我应该给我一个5秒的剩余时间。
#Get the number of seconds
total_secs = int(input("How many seconds, in total? " ))
#calculate those seconds into days
days = total_secs // 86400
secs_days = total_secs % 86400
#calculate the remainder into hours
hours = secs_days // 3600
secs_hours = secs_days % 3600
#calculate the remainder into minutes
minutes = secs_hours // 60
secs_minutes = secs_hours % 60
#calculate the remainder into seconds
seconds = secs_minutes // 60
#print out days if the number is above 0
if days == 0:
print(" ")
else:
print("Days=", days)
#print the number of hours & minutes
print("Hours=", hours)
print("Minutes=", minutes)
#print out seconds if the number is above 0
if seconds == 0:
print(" ")
else:
print("Seconds=", seconds)
print('Thank you')
答案 0 :(得分:0)
嗯,你有一个逻辑错误
seconds = secs_minutes // 60
实际上应该只是
seconds = secs_minutes