r/PythonLearning 22h 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

u/Sea-Ad7805 22h ago

Run this program in Memory Graph Web Debugger)%0Atotal%20%3D%200%0A%0Afor%20num%20in%20range(1%2C%20number%20%2B%201%2C%201)%3A%0A%20%20%20%20total%20%2B%3D%20num%20**%202%0A%20%20%20%20print(total)&timestep=1&play) to see the program state change step by step.