+ 1
Finding time difference between 2 times
can any help me, I want to introduce minutes also in this code
8 Respostas
0
I cant see any codes but, if u want date and time in your code use:
import datetime
0
I'm sorry but my teacher said do without date time library
0
You could transform the times into seconds (How many seconds have gone by since midnight?). Calculate the difference of the two and then transform them back. For more help you should provide the time-format.
0
As it is your homework, try on your own first, then post a code (I mean create a code in the playground and link it) and ask for help if you're stuck with something.
It is your task for a reason :)
0
yeah I made a code but I don't know how to insert it here ...lol
0
@ranvir okay then, do you know where playground is? Open the tab and click green button with a plus to add your code and make it public. Then you can add a post and insert your code in here ("Insert" button on the left to the "Post")
If you wrote your code on desktop you might want to use SoloLearn desktop version
0
I have posted it in my profile. Can somebody test it. Thank you
0
Your code works fine as far as I can see, but oh boy, how much easier your life would be with 24-hour format. I suggest you using function, maybe something like this
def converter(str):
hour = int(str[:str.find(":")])
if str.find("p"):
hour +=12
minutes = int(str[str.find(":")+1:str.find("p")-1])
else:
minutes = int(str[str.find(":")+1:str.find("a")-1])
t = [hour, minutes]
return t
With it you'll obtain 24-hour equivalent of the user input. Then you just pass your string to function and assign resulting values to respective variables.
I hope the use of functions is not restricted. That way you won't need as many nested if statements, though the logic stays the same