Skip to content
Sign upLog in
← Back to Community

Factorial CodeHS. Please help :)

Profile icon
SimplyMiah

Hello Repel community,
I am stuck on a CodeHS python question titled: Factorial. Can you guys please help me with this, it means the world to me, thank you <3
Here is the problem :)

Write a program that prints out a factorial. N factorial (written N!) is defined as

N * (N-1) * (N-2) * ... * 1
For example, 4! is

4 * 3 * 2 * 1 = 24
Ask the user for the value of N. Use for loops and variables to print out N factorial.

(Hint: You solve factorial by multiplying the numbers from 1 all the way up to N together. You need a variable to store the result.)

Voters
Profile icon
SimplyMiah
Comments
hotnewtop
Profile icon
MocaCDeveloper
def factorial(number): fact = 1 for i in range(number+1): if not i == 0: fact = i*fact print(fact) return fact # this will store the total value, don't worry about this num = factorial(int(input("Value -> ")))

OR THIS

import math value = int(input("value -> ")) for i in range(value+1): if not i == 0: print(math.factorial(i))