#๐ i dont understand this part in the code
64 messages ยท Page 1 of 1 (latest)
@sharp forum
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
the thing i dont understand is the modulus 60 (% 60) part
the so called f-string?
No this
i dont understand how the % 60 works to make the timer work as it's supposed to
like
with modulus 60
its normal
if i put 61 secs it displays as 1 min and 1 sec
if i remove it it becomes 1 min 61s
do you know how modulus works?
it gives you the reminder
yea ik that part but i cant get mysefl to understand how it fits into this code to make it work
so, if you divide 61 with 60, it gives the reminder 1
as there is 60 seconds in (almost) every minut and 60 minutes in every hour you can use modulus
so basically since minutes/secs are divided by 60
we put the dividend as 60
so
in secs/mins
the remained is the seconds
and the times it divies is minutes
ok i understand now
there is a great function called divmod() that does both at the same time
thx
hold on
import time
mytime = int(input("Enter time(s): "))
for x in (range(mytime, 0, -1)):
seconds = x % 60
minutes = int(x / 60) % 60
hours = int(x / 3600)
print(f"{hours:02}:{minutes:02}:{seconds:02}")
time.sleep(1)
print("TIME'S UP!")
Hey @sharp forum!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
import time
mytime = int(input("Enter time(s): "))
for x in (range(mytime, 0, -1)):
seconds = x % 60
minutes = int(x / 60) % 60
hours = int(x / 3600)
print(f"{hours:02}:{minutes:02}:{seconds:02}")
time.sleep(1)
print("TIME'S UP!")```
can u implement it please?
im learning from a course video
!e
print(divmod(65, 60))
and where should i place this in the code
:white_check_mark: Your 3.13 eval job has completed with return code 0.
(1, 5)
see how it gives you both the division and the reminder (result of the modulus operation) as a tuple of two elements?
also, you don't need to do int(x / 60) there is a integer division operator in python, it's //
!e
print(int(65 / 60))
print(65 // 60)
:white_check_mark: Your 3.13 eval job has completed with return code 0.
001 | 1
002 | 1
see how you get the same result from them?
i see, which one do you fallow?
which one, do you mean divmod()?
brocode
#python #tutorial #beginners
Python tutorial for beginners' full course 2024
Learn Python in 1 HOUR โฑ : https://www.youtube.com/watch?v=8KCuHHeC_M0
Learn NumPy in 1 HOUR ๐ข (2025): https://www.youtube.com/watch?v=VXU4LSAQDSc
My original Python 12 Hour course ๐ : https://www.youtube.com/watch?v=XKHEtdqhLK8
Full Python playlist ...
skip to uh
2:15:00
if u wanna get to the part where i am
12h, not a fan of those long videos
but if it works for you that's good, we are all different
mhm alr thx
yup
you would change
seconds = x % 60
minutes = int(x / 60) % 60
```to
```py
minutes, seconds = divmod(x, 60)
and if i add hours too?
first paragraph yea got it
hours = int(x / 3600) % 24(if i add days)
but the 2nd?
as x is the total number of seconds you still need the hours = x % 3600
sure, there are other "basic" ways to do it too, but i don't know if they are that much better
you could do:
minutes, seconds = divmod(x, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.