How do you calculate minutes in python?
I have a task in which i need to calculate the runtime of a marathon. I'm given this as a start point Show
Basically the start is at 3:48 and it continues for 172 minutes. My task is to find when the marathon ends.The endtime should look like this format 3:48 with minutes and hour converted to string and put together with ":". I have spent like 1 and a half hour and i still can't manage to solve it. This is what i have come out with:
But when i print the final hour is shorter then it should be with 1 hour. I'm guessing that i need to do something with the > or < but i really can't figure it out.I guess that i only need that final push. offtopic: I'm very new to proggraming i don't have experience whatsoever. asked Aug 14, 2017 at 11:42
You can use some
If you want to get rid of the
I prefer this approach because it accounts for edge cases like starting one day near midnight and ending in the next day. answered Aug 14, 2017 at 11:50
4 I would suggest
After initializing the end hour and minute as you did, you extract again the minutes and hours from the end minutes. Finally, you adjust the hours to be between 0 and 23. answered Aug 14, 2017 at 11:46
UrielUriel 15k6 gold badges24 silver badges46 bronze badges How about keeping everything in minutes and then working out the output as intended later? Keeping it simple to understand and read :)
answered Aug 14, 2017 at 11:50
shad0w_wa1k3rshad0w_wa1k3r 12.6k8 gold badges65 silver badges88 bronze badges Use
This assumes that you don't expect anyone to finish after midnight/the next day. If you want to account for that possibility you can take the modulus of answered Aug 14, 2017 at 12:07
BatmanBatman 8,3077 gold badges39 silver badges76 bronze badges let's keep it simple
or
answered Apr 19, 2020 at 12:09
Keeping it simple! :)
answered Mar 23, 2020 at 14:19
1 Keep it short and simple
answered Dec 10, 2020 at 15:27
Suraj Rao 29.1k11 gold badges95 silver badges100 bronze badges answered Feb 12 at 8:05
1
This may helps answered Feb 17 at 22:11
1 I suggest the following,
think is much simple solution :) answered Apr 11, 2020 at 23:13
How does Python calculate time?Use the below functions to measure the program's execution time in Python:. time. time() : Measure the the total time elapsed to execute the code in seconds.. timeit. ... . %timeit and %%timeit : command to get the execution time of a single line of code and multiple lines of code.. datetime.. How do I get hours and minutes in Python?To get the current time in particular, you can use the strftime() method and pass into it the string ”%H:%M:%S” representing hours, minutes, and seconds.
How do you calculate the number of minutes between two times in Python?timedelta() method. To find the difference between two dates in Python, one can use the timedelta class which is present in the datetime library. The timedelta class stores the difference between two datetime objects.
How do I convert time to minutes in Python?Python Program to Convert time into minutes. def convert_time(hrs, min):. min= hrs*60+min.. return min.. h=int(input("Enter the hours:")). m=int(input("Enter the minutes:")). m=convert_time(h,m). print("Total Minutes=",m). |