Question

IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns...

IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].

0 1
Add a comment Improve this question Transcribed image text
Answer #1
def intToList(n):
    if n == 0:
        return [0]
    else:
        lst = []
        while n > 0:
            lst.insert(0, n % 10)
            n //= 10
        return lst


print(intToList(123))

\color{blue}Hey,\;Please\;let\;me\;know\;if\;you\;need\;me\;to\;make\;any\;changes. \\ I\;would\;really\;appreciate\;an\;upvote.\;Thank\;you!

Add a comment
Know the answer?
Add Answer to:
IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT