```
i=int(input('Enter a postive integer '))
while i <:
print('before ',i)
i=i * (i-1)
print('after ',i)
print('next')
```

i have tries in different ways but i am not able to write logic for factorials

```
i=int(input('Enter a postive integer '))
while i <:
print('before ',i)
i=i * (i-1)
print('after ',i)
print('next')
```

i have tries in different ways but i am not able to write logic for factorials

Use for loop don’t use while loop for this question

so in case of factorial for 5, start with number before the loop as y = 1 and then update its value in loop by multiplying by loop numbers. Final value of y becomes factorial

```
y = 1
for i in range(1,5):
# update the value of y here
```

```
y=2
for i in range(1,5):
print(i*y)
```

this is not giving factorial it is just giving 2,4,6,8

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