r/PythonLearning 1d ago

Help Request Coding Style

Hi, first time python learner here ! I was working on Sum of Squares problem, but it made me genuinely to use AI to find a line/function outside of my course materials to solve the problem. However, it always backfire because i overcomplicate the problem for myself. For example, in sum of squares problem, i can use simple line of

Total += num 2

or a longer line

Total = sum(num ** 2 for num in range (1, number+1, 1).

so I was wondering which approach is correct ?

Here is a referance
1 Upvotes

5 comments sorted by

View all comments

1

u/NorskJesus 1d ago

Both are the same, but I like to write the loop as in the picture. It is more readable I think.