GitHub Repository Submission

When using GitHub mode, paste your repository URL below and click Save URL to store it. The saved URL will be automatically included with every message you send until you choose to clear it. Learn more

Your GitHub repository URL is saved. LSBot will automatically fetch your latest code from this repository for each message. To change the URL, clear it first and save a new one.

Exercise 2

This question may be a little challenging if your math skills are rusty. Don't be afraid to take advantage of the hints. Try your best to solve the problem, but don't feel compelled to complete it if you become frustrated.

Use the REPL and the arithmetic operators to extract the individual digits of 4936:

  1. One place is 6.
  2. Tens place is 3.
  3. Hundreds place is 9.
  4. Thousands place is 4.

Each digit may require multiple Python statements.

It's easier to extract the digits right-to-left rather than left-to-right.

number % 10 returns the rightmost digit of a number. You can use this repeatedly to extract all of the digits.

Once you have the rightmost digit, how do you remove that digit from the number? If we start with 4936 and extract the 6, how do we now reduce our number to 493?

You can remove the rightmost digit by using integer division.

Solution

>>> number = 4936
>>> ones = number % 10
>>> ones
6

>>> number = number // 10
493

>>> tens = number % 10
>>> tens
3

>>> number = number // 10
49

>>> hundreds = number % 10
>>> hundreds
9

>>> thousands = number // 10
>>> thousands
4

Note that you don't need to use % for the thousands digit.

Video Walkthrough

Hi! I'm LSBot. I can help you think through the selected exercise by giving you hints and guidance without revealing the solution. Your code from the editor will be automatically detected. Want to know more? Refer to the LSBot User Guide .

Detected solution
Loading...

Submit your solution for LSBot review.

Hi! I'm LSBot. Your code from the editor will be automatically detected. I'll review your solution and provide feedback to help you improve. Ask questions about your solution or request a comprehensive code review. Want to know more? Refer to the LSBot User Guide .

Detected solution
Loading...