I'm looking at a challenge to build a Floyd's triangle out of integers using only arithmetic operators and a single for-loop. There are hundreds of tutorials using dual for-loops and string operations, but I haven't seen anything using math.
Example output using repeating integers:
1
22
333
4444
I'm approaching the solution logic like so:
1 * (1) = 1
2 * (1 + 10) = 22
3 * (1 + 10 + 100) = 333
As a newb Python learner I can't construct the logic loop. Any ideas or alternative approaches? No string operations allowed here, just math!
this works for me :)
n = 4
val=0
for i in range(n):
val+=10**i
print(val*(i+1))
Val is 1, then 11, then 111. I'm not sure if this is what you are expecting.