input time, increase the sec +1

Hi, i'm trying to write a simple program without using the time function. The program will ask user for current time, then it will add 1 sec to the time and display the time. How to add the 1 sec and also add the change to minutes and hours? and without using if statements.

You are viewing a single comment. View All
abc3354 (215)

Hi :)
You can use integer division (//) and modulo (%)

When the user input a time, convert this time in seconds
10:53:32 => 39212
Then you can add what you want
Then convert it again

A simple hint : 39212 % 60 == 32 (number of seconds)

Good luck ;)

Replit helper here !

sharkquik (0)

@abc3354 Thank you so much!
1. I have another question, how to display the time in 00:00:00 format
2. For 24:00:00, I want it in 00:00:00

abc3354 (215)

@sharkquik, with modulos you should have 00
try to divide the big number of second by 3600 and then to do modulo 24 to have the number of hours

sharkquik (0)

@abc3354 Thanks for your help! I changed the print format to {:02d} and did the modulo that you suggested. It works.