Jun-13-2017, 02:01 PM
You were on the right track with your first example, almost. Then you were correct in thinking you needed to use 'range'. Then you sort of went berserk. Many times in reply's you will see the advise "add print statements". This helps you to "see" what the script "sees". Once your satisfied, you can delete the print statements.
I've taken the liberty of modifying your code a bit:
I've taken the liberty of modifying your code a bit:
def factorial(number): for n in range(1, number): # Gives range 1 thru number - 1 print('number {} times {}'.format(number, n)) # Go ahead and delete this line number *= n print("number = ", number) # Go ahead and delete this line return number selection = int(input("Pick a number between 1 and 18: ")) result = factorial(selection) print("{} objects can be arranged {} different ways".format(selection, result))
Output:Pick a number between 1 and 18: 5
number 5 times 1
number = 5
number 5 times 2
number = 10
number 10 times 3
number = 30
number 30 times 4
number = 120
5 objects can be arranged 120 different ways
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition