#๐ Python
68 messages ยท Page 1 of 1 (latest)
@little anchor
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.
1200 divided by 3000 is 0.4 you are right, but
As 1200 is less than 3000, it cannot divide even once, so the remainder is 1200
a%b==c when a = b*(a//b)+c
1200//3000 is 0
So the remainder is 1200-0*3000 = 1200
I don't know why you think it should be 4 "because it's 0.4"
1200/3000 (normal division) is 0.4... But that doesn't have any *10 there? 
Or were you thinking that a%b means "how many percent of b is a?" - but then you'd expect 40, not 4...
in other words, what did you think the % operator does @little anchor ?
It's the reminder?
*remainder
But it's better known as the "modulus operator"
yes, and if you divide 1200 by 3000, how many times does 3000 fit in 1200, and how much is left over after the division?
I tried to do like how many hours and minutes in 5000 second but look at last line it says wrong
can you please at least answer my question?
also, please learn how to use the screen capture tool rather than taking photos of your screen
Yes I anderstund there is no reminder but what should I do instead
What is this I'm new
Learn how to use Snipping Tool to capture a screenshot, or snip, of any object on your screen, and then annotate, save, or share the image.
what you probably want is divmod()
!e
hours, seconds = divmod(5000, 3600)
minutes, seconds = divmod(seconds, 60)
print(f"{hours} h, {minutes} m, {seconds} s")
print(hours * 3600 + minutes * 60 + seconds)
:white_check_mark: Your 3.14 eval job has completed with return code 0.
001 | 1 h, 23 m, 20 s
002 | 5000
Sorry I don't know much in laptop can you help with this picture
๐ซจ๐ซจ
!e
# an alternative way
minutes, seconds = divmod(5000, 60)
hours, minutes = divmod(minutes, 60)
print(f"{hours} h, {minutes} m, {seconds} s")
print(hours * 3600 + minutes * 60 + seconds)
:white_check_mark: Your 3.14 eval job has completed with return code 0.
001 | 1 h, 23 m, 20 s
002 | 5000
does this way make more sense to you?
Do you know that I'm begganer?what is devmod ? Or should I wait and I will understand later in advance
I gave you a direct link to its documentation โ did you read it?
it makes a division and returns you the quotient and the remainder in one shot
quite convenient for operations like this
Yes didn't understand the translate is bad
Ok maybe over time in learning I will use this
Thank you
:white_check_mark: Your 3.14 eval job has completed with return code 0.
(3, 1)
so 10 // 3 == 3 and 10 - 10 // 3 == 1, easy enough?
let me know if there's something you don't understand
!e print((10 - 10 // 3) == 1)
:white_check_mark: Your 3.14 eval job has completed with return code 0.
False
woops
I suppose 10 - 10 // 3 * 3 == 1 would have been better, but that does get a bit complex looking
it was intended to show that the remainder from the integer division would be 1
I understand this
alright โ if there's nothing else, you can do !close
divmod() is just a shortcut for // and % combined, eg:
minutes = seconds // 60
seconds = seconds % 60
# is equal to
minutes, seconds = divmod(seconds, 60)
I don't know divmod yet i will wait until I learn it thank you
BTW, in your example:
hours = seconds // 3600
rest_hours = seconds % 3600
the rest_hours are still seconds and not minutes like you have printed.
Yes I was going to ask that
Buy why
Because you used the seconds, a modulo operation will not convert them to minutes.
1 hour == 3600 seconds, 5000 - 3600 == 1400 but still seconds
Sorry but how did that printed at result
I typed (+str (rest_hour ) which is the reminder of (5000/3600) that is should be (38)
Because 5000/3600 is 1.38
!e
print(5000 / 3600)
print((5000 / 3600 - 1) * 3600)
:white_check_mark: Your 3.14 eval job has completed with return code 0.
001 | 1.3888888888888888
002 | 1399.9999999999998
So, no -> 5000 % 3600 is 1400
The remainder of a division is not the fraction part of the result. It is the whole number which does not get used by the division.
Oh thank you I didn't know now I understand
Now it's done thank you๐ฅณ๐ฅณ
It would be more accurate to name them rest_secondes (and rest_minutes).
@little anchor
go to windows search
bottom left of your screen Type here to search
and then type snipping tool
then click the program that shows up
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.