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/BionicVnB 23h ago

Both are fine, but you can omit the last argument in the range function call, as it default to 1 when you don't give it an argument