Apr-09-2017, 06:57 AM
Tried what?
help in hoemwork
|
Apr-09-2017, 06:57 AM
Tried what?
Apr-09-2017, 07:10 AM
recursia..
never mind
Apr-09-2017, 07:33 AM
Look, this is your homework. We will help you to do it but we are not going to write it for you.
You're saying you tried recursion. Post the code to see why is not working. A simple example: def factorial(n): if n == 1: return 1 else: return n * factorial(n-1)
Apr-09-2017, 10:52 AM
You don't need recursion. I just showed you how to modify part of your program, you have to put that back into the while loop you already had. So yes, one pass through the code I showed you takes 74 to 11. Then the while loop runs through it again and 11 becomes 2. Then the while loop stops and returns the 2 you want.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures
Apr-17-2017, 02:43 AM
I recently just picked up python so I may not have the best answer...I have already solved it though.
My code has 2 functions. One function to count how many digits are in the number and another function that adds the digits in a number together. I used a FOR loop to iterate through the number , adding each individual digit to a list. After that I made a variable to hold the sum of the numbers in the list. My digit counting function counts the digits of the "final answer" , I then used a IF/ELSE statement to determine whether the digits could be added together further. If not return the "final answer" if yes then repeat.
Apr-17-2017, 06:59 PM
Test everything in a Python shell (iPython, Azure Notebook, etc.)
|
|