+ 3
Please, help me. I have to write program, but I don`t know how to do it . You have amount of seconds . You must to arrange it in format: hour:minutes:seconds. For example, 26746 seconds - it is 07:25:46.
4 Antworten
+ 2
hi, do you mean, you habe to write amount of seconds and then print how much hours,minutes and seconds, in that case, you shoud use
a = int(input())
minutes= a // 60
secondsleft = a % 60
hours = minutes // 60
minutesleft = minutes % 60
you can also use divmod for this if you want, in that case minutes,secondsleft divmod(a,60)
hours, minutesleft divmod(minutes,60)
print(hours \nminutesleft\nsecondsleft
+ 2
I'm sorry, but it don,t work. If I write, for example, 57653 - he show, that it have 960 minutes. In adiction, I want to use zeros in programm. For example, 06:08:03, insteed of 6:8:3. Unfortunatly, it is the hardest part of program.
+ 2
# try this one
time = int(input('Please enter the time in seconds : '))
hr = time // 3600 # calculates the hours
min = ( time % 3600) // 60 # calculates the minutes
sec = ((time % 3600) % 60) // 1 # seconds
# displaying the result
print(str(hr) + 'hours ' + str(min) + 'minutes ' + str(sec) + 'seconds ')
+ 1
you will need if for this. if seconds < 10 :
string(seconds)- or somehow convert it to string i forgot.
seconds = "0" + seconds
if minutesleft < 10:
str(minutes)
minutesleft = "0" + minutesleft
same for hoursleft
print( hoursleft, minutesleft, seconds)