#๐Ÿ”’ i dont understand this part in the code

64 messages ยท Page 1 of 1 (latest)

sharp forum
median oreBOT
#

@sharp forum

Python help channel opened

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.

sharp forum
#

the thing i dont understand is the modulus 60 (% 60) part

wraith moss
sharp forum
#

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

wraith moss
#

do you know how modulus works?

sharp forum
#

well now im questioning it lol

#

๐Ÿ˜ญ

wraith moss
#

it gives you the reminder

sharp forum
#

yea ik that part but i cant get mysefl to understand how it fits into this code to make it work

wraith moss
#

so, if you divide 61 with 60, it gives the reminder 1

sharp forum
#

hm

#

oh

#

I GET IT NOW

#

tysm

wraith moss
#

as there is 60 seconds in (almost) every minut and 60 minutes in every hour you can use modulus

sharp forum
#

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

wraith moss
#

there is a great function called divmod() that does both at the same time

sharp forum
#

thx

sharp forum
#

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!")

median oreBOT
#

Hey @sharp forum!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
sharp forum
#
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

wraith moss
#

!e

print(divmod(65, 60))
sharp forum
#

and where should i place this in the code

median oreBOT
wraith moss
#

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)
median oreBOT
wraith moss
#

see how you get the same result from them?

wraith moss
wraith moss
sharp forum
#

brocode

#

skip to uh

#

2:15:00

#

if u wanna get to the part where i am

wraith moss
#

12h, not a fan of those long videos
but if it works for you that's good, we are all different

sharp forum
#

mhm alr thx

sharp forum
wraith moss
# sharp forum yup

you would change

    seconds = x % 60
    minutes = int(x / 60) % 60
```to
```py
    minutes, seconds = divmod(x, 60)
sharp forum
#

and if i add hours too?

#

first paragraph yea got it

#

hours = int(x / 3600) % 24(if i add days)

#

but the 2nd?

wraith moss
#

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)
median oreBOT
#
Python help channel closed for inactivity

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.