[Tutor] For Loops Program Issue

P L la_spirou at hotmail.com
Wed Aug 19 05:00:22 EDT 2020


Your range will be whatever input that is given. There's no need to include the result variable in the input range. Second issue, you can simplify the formula even more:  result *= ? followed by a second line of instructions for n.

Best of luck,
Pat

________________________________
From: Tutor <tutor-bounces+la_spirou=hotmail.com at python.org> on behalf of eric grunfeld <grunfelderic at gmail.com>
Sent: August 18, 2020 11:17 AM
To: tutor at python.org <tutor at python.org>
Subject: [Tutor] For Loops Program Issue

Good Morning Everyone:

I am currently taking a beginners Python course that is being taught by
Google, on the Coursera platform.

I have been working on a problem but I seem to be obtaining an error
message after running the program.

Here is the problem:

def factorial(n):
    result = 1
    for i in range(result,n):
        result = result * n+1
    return result

print(factorial(4)) # should return 24
print(factorial(5)) # should return 120:

Here is the the error message that I have been receiving:

Here is your output:
85
781

Not quite. Pay attention at the operations that the code is
doing and make sure that the factorial function returns the
product of the numbers between 1 and n.

Based upon my understanding, it appears that my issue is with the set-up of
my range.

I look forward to any thoughts or comments that you may have.

All the best,
Eric
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutor&data=02%7C01%7C%7C9a64081af0b4445256f908d8438f7510%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637333630700211531&sdata=2FG3qR%2Fdv21fjRG1j0BoWVrzDl5YY9fdt4qSurIJ%2Fjw%3D&reserved=0


More information about the Tutor mailing list