Logic Building
# Take n
n = int(input("Enter n: "))
# Calculate sum of cubes
total = 0
for i in range(1, n + 1):
total += i * i * i
print(f"Sum of cubes: {total}")Output
Enter n: 5 Sum of cubes: 225
Sum cubes of numbers from 1 to n.
Key Concepts:
- Loop from 1 to n
- Calculate i * i * i
- Accumulate sum