#๐Ÿ”’ Reversing a number

43 messages ยท Page 1 of 1 (latest)

velvet hazel
#

example : 2000 sens = 20 ringgit
Example : 200 sens = 2 ringgit

lost ivyBOT
#

@velvet hazel

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.

velvet hazel
#

Don't mind the title is the wrong one

tacit meteor
#

!title Reversing a number

lost ivyBOT
#

Reversing a number

safe fox
#

Have you encountered the floor division and modulo operators // and %?

#

Alternatively, the divmod function?

#

@velvet hazel

#

A while loop may also be applicable here.

velvet hazel
#

Yeah

#

// this is modulus

#

I forgot this symbol %

tacit meteor
#

% is modulus

safe fox
#

Some interesting behaviour jumps out when you use a particular value as the righthand operand.

#

!e py print(123 // 10) print(123 % 10)

lost ivyBOT
safe fox
#

!e py print(format(0xabc // 16, 'x')) print(format(0xabc % 16, 'x'))

lost ivyBOT
safe fox
#

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)

lost ivyBOT
safe fox
#

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.

velvet hazel
#

So basically modulous is numbers with remainders?

#

And % is without remainders

#

So how do I do it

gilded halo
velvet hazel
#

// what is this called then

gilded halo
velvet hazel
#

which one is with the remainders

gilded halo
safe fox
#

The other way to do this is as a string, but they've asked you to do it mathematically.

#

!e py print('123'[::-1])

lost ivyBOT
lost ivyBOT
#
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.