# Can you help me to check the program code error?

**URL:** <https://forum.codewithmosh.com/t/can-you-help-me-to-check-the-program-code-error/1613>\
**Category:** Python\
**Created:** [January 2, 2021, 8:27am UTC](https://forum.codewithmosh.com/t/can-you-help-me-to-check-the-program-code-error/1613 "2021-01-02T08:27:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunlight](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sunlight](https://forum.codewithmosh.com/u/sunlight)\
**Post date:** [January 2, 2021, 8:27am UTC](https://forum.codewithmosh.com/t/can-you-help-me-to-check-the-program-code-error/1613/1 "2021-01-02T08:27:34Z")

</div>

Recently, I use pycharm to practice typing some codes, but I encounter with some problems, the factorial of 5 should be output. But the output is only 5. Could you please take some time to help me check the errors? I will appreciate for that!

The code as follows:

def factorial(n):  
r = 1  
while n \> 1:  
r \*= n  
n -= 1  
return r

print(factorial(5))

---

<div class="post-metadata">

**Author:** ![david\_ke](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@david\_ke](https://forum.codewithmosh.com/u/david_ke)\
**Post date:** [January 3, 2021, 8:07am UTC](https://forum.codewithmosh.com/t/can-you-help-me-to-check-the-program-code-error/1613/2 "2021-01-03T08:07:48Z")

</div>

I’m just new to Mosh’s tutorials on YouTube, so I haven’t yet gotten to the functions lesson. But I used a for loop to solve your problem. Check out the solution below 🙂

x = int(input("Please enter a number: "))  
numbers = []  
for item in range(1,x+1):  
numbers.append(item)  
numbers.reverse()

factorial = 1  
for item in numbers:  
factorial = factorial \* item

print(f"The factorial of the number you entered is {factorial}")

---

<div class="post-metadata">

**Author:** ![Bigrevkev55](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/bigrevkev55/32/522_2.png) [@Bigrevkev55](https://forum.codewithmosh.com/u/Bigrevkev55)\
**Post date:** [January 3, 2021, 3:29pm UTC](https://forum.codewithmosh.com/t/can-you-help-me-to-check-the-program-code-error/1613/3 "2021-01-03T15:29:07Z")

</div>

Does this help?

 ![image](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/1X/72d9530b31541c216f54e01e38e201da32099201.png)

---

<div class="post-metadata">

**Author:** ![Minnie](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@Minnie](https://forum.codewithmosh.com/u/Minnie)\
**Post date:** [January 3, 2021, 5:48pm UTC](https://forum.codewithmosh.com/t/can-you-help-me-to-check-the-program-code-error/1613/4 "2021-01-03T17:48:33Z")

</div>

try this:

import math

print(math.factorial(5))

\*\*you need to import the math module first and you dont need all those codes at all.

---

<div class="post-metadata">

**Author:** ![sunlight](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@sunlight](https://forum.codewithmosh.com/u/sunlight)\
**Post date:** [January 4, 2021, 2:53am UTC](https://forum.codewithmosh.com/t/can-you-help-me-to-check-the-program-code-error/1613/5 "2021-01-04T02:53:00Z")

</div>

I know the reason, your advice is really helpful, thank you all!
