#๐ Reversing a number
43 messages ยท Page 1 of 1 (latest)
@velvet hazel
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.
Don't mind the title is the wrong one
!title Reversing a number
Reversing a number
Have you encountered the floor division and modulo operators // and %?
Alternatively, the divmod function?
@velvet hazel
A while loop may also be applicable here.
% is modulus
Some interesting behaviour jumps out when you use a particular value as the righthand operand.
!e py print(123 // 10) print(123 % 10)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 12
002 | 3
!e py print(format(0xabc // 16, 'x')) print(format(0xabc % 16, 'x'))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | ab
002 | c
In hex.
As with regular numbers, they're in base ten.
So 10 as the righthand.
With hex values, that's base 16, so 16 as the righthand.
!e print(0xabc)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
2748
For binary, 2. Octal, 8.
You don't need to know about this specifically, just that you're working with the base on the right.
Hence 10, because that's what we represent numbers as.
Typically.
123 divides by 10 fully 12 times, with 3 left over. 12, 3.
Floor division, modulo.
So basically modulous is numbers with remainders?
And % is without remainders
So how do I do it
% is modulous
// what is this called then
floor division
which one is with the remainders
modulous
The other way to do this is as a string, but they've asked you to do it mathematically.
!e py print('123'[::-1])
:white_check_mark: Your 3.12 eval job has completed with return code 0.
321
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.