+ 1

Can someone help me again

Can anyone solve how to code these test A number's factorial is the product of all positive integers less than or equal to the number. Write a program that takes a number as input and outputs its factorial to the console. Sample Input 5 Sample Output 120 Explanation 5*4*3*2*1 = 120

22nd Apr 2021, 7:36 AM
Darren Ardhianata
Darren Ardhianata - avatar
15 Respostas
+ 3
fix the bugs, edit the code, and show what you've got
22nd Apr 2021, 9:00 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
you have a syntax error after the parentheses in the for condition - after the parentheses should go immediately curly. think about the loop condition. why do you have the factorial variable equal to one and you compare the unit with the input value of number. think about whether the loop will be executed if number is equal to five? and you don't do anything with the factorial variable in the loop. once again, you write a program to calculate the product of all the numbers sequentially. product means multiplication
22nd Apr 2021, 8:58 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
after fixing the errors, your code will not be perfect yet, but suddenly you will succeed. I redid it and it worked. although I also solved this problem for a long time
22nd Apr 2021, 9:09 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
*I tried to solve it for a long time
22nd Apr 2021, 9:10 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
Darren Ardhianata import math as m print(m.factorial(5)) I know you seem a beginner But this code will work If you want a explaination Ask me
23rd Apr 2021, 12:07 PM
Aditya
Aditya - avatar
+ 1
Hi! Please, for better help, show us your code attempt first!
22nd Apr 2021, 7:38 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
it's not java, it's javascript. please do not confuse them. they are completely two different languages. insert your code into the coding pad by selecting "web" and the "js" section
22nd Apr 2021, 7:46 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Thank you i got it now
22nd Apr 2021, 9:06 AM
Darren Ardhianata
Darren Ardhianata - avatar
0
Oh
22nd Apr 2021, 7:49 AM
Darren Ardhianata
Darren Ardhianata - avatar
22nd Apr 2021, 7:49 AM
Darren Ardhianata
Darren Ardhianata - avatar
0
There
22nd Apr 2021, 7:50 AM
Darren Ardhianata
Darren Ardhianata - avatar
0
It should like this fact=1 for(i=2;i<=n;i++) fact=fact*i print(fact) It is just algorithm not in any language you can convert it into any language you want and also n=the number for which you want to calculate factorial
22nd Apr 2021, 2:45 PM
YUGRAJ
0
And also print statement is outside for loop
22nd Apr 2021, 2:46 PM
YUGRAJ
22nd Apr 2021, 4:41 PM
born2code
born2code - avatar
- 1
I think above 👆 code will help u
22nd Apr 2021, 4:41 PM
born2code
born2code - avatar