-3

Hi I'm trying to solve this problem:

"For any number code the next series:"

n = any number (1 for this case)

1,2,6,24,120,720...

This series is:

1x1 = 1

1x2 = 2

2x3 = 6

6x4 = 24

24x5 = 120

And so on....

I don't know how keep the first value (maybe a cont=0) and how use the for loop or the while loop.

Any idea?

Cain9745
  • 41
  • 3

2 Answers2

0

You're keeping track of two different numbers here -- there's the number that's produced in the series (n) and the number that you're multiplying each successive n by (let's call that k). So the natural thing is to have a loop that iterates over the values in k and multiplies each one by n to get the next value of n:

>>> n = 1
>>> for k in range(1, 6):
...     print(f"{n}x{k} = ", end="")
...     n *= k
...     print(n)
...
1x1 = 1
1x2 = 2
2x3 = 6
6x4 = 24
24x5 = 120
Samwise
  • 68,105
  • 3
  • 30
  • 44
0

I hope the following code can help you
maybe you can try to make this question simpler
This is my solotion, and it works

start=1
stop=10 # you can set your own
for a in range(1,stop+1):
    print("{}*{}=".format(start,a),end='')
    start=start*a
    print(start)
Rduan
  • 38
  • 4
  • Sorry, I didn't saw that @Samwise already answer it when I post my own, his solution is brilliant! – Rduan Aug 15 '22 at 01:45