Factorial, HELP PLEASE!


#1

https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/5?curriculum_id=4f89dab3d788890003000096

_My code is working fine, but it's not working the way I want it to._  
**def factorial(x):**
**    if x ==1:**
**        print 1**
**    while x>1:**
**        x-=1 **
**        print x **
**factorial(4)**
The above code will count down from 4. However, I want it to include the number 4 and not just start counting down. I managed to fix this issue, but doing so conflicted with the goal of the assigment --> multiplying the numbers together. 
Any help is appreciated, but please do not go above what I asked. In other words, don't solve the rest of the assignment as I want to solve it by myself. 
Thanks in advance :)


#2

def factorial(x):
temp = x

if temp == 1:
    print temp
if temp >= 2:
    print temp
    x -= 1

Your issue was in the decrement location. If you decrement before printing, you will only see the decremented value and no the initial value (in your case 4).


#3

Thank you very much!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.