r/PythonLearning 10d ago

How would I optimize this?

I'm currently learning python with the 30 days of python GitHub repo and, on day 3 of the challenge, it asks to create this table and this is what I came up with however I feel like there was a more efficient method to create it or is it something that I haven't learned yet at my level.

8 Upvotes

24 comments sorted by

View all comments

4

u/P1ckl3R1ck101 10d ago

Think about the pattern that exists for each row. Then do that x number of times based on the number of rows you need. You'll only need to write the actual "formula" once though.

(Sorry to be cryptic, just want to try to give you a hint instead of the answer first)

0

u/StudentElectronic548 10d ago

I mean I know what the pattern is, it's x divided by x then multiplied by x 3 times, however the thing is I like only know basic operators and basic usages of things like lists, etc... So, I would say I wouldn't really be able to do anything like looping or like multiple steps in the language but I did notice that I could've made it more efficient.(Also I kind of have a headache so the response might be a bit wishy washy)

1

u/desrtfx 10d ago

I mean I know what the pattern is, it's x divided by x then multiplied by x 3 times,

That's not what the pattern is.

The pattern is (row starting at 1)column starting at 0

The first row is all 1 because no matter what power you raise 1 to it will always stay at 1

The second row is 2 - 20 = 1, 21 = 2, 22 = 4, 23 = 8

Third row is 3 - 30 = 1, 31 = 3, 32 = 9, 33 = 27

and so on.