From 834be3605184868c405000aa76a7deededdf0171 Mon Sep 17 00:00:00 2001 From: Jaswanth M <102037032+Jaswanth02004@users.noreply.github.com> Date: Mon, 16 Nov 2026 07:02:07 +0530 Subject: [PATCH] Refactor sumOfSeries for precision and user input Updated sumOfSeries function to use integer division for precision and changed input method to prompt user. --- ARKA.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ARKA.py b/ARKA.py index 0132c4ce541..c529b22993a 100644 --- a/ARKA.py +++ b/ARKA.py @@ -1,8 +1,19 @@ def sumOfSeries(n): - x = n * (n + 1) / 2 - return (int)(x * x) + x = n * (n + 1) // 2 #// and return x * x: Keeps the calculation in exact integers with zero precision loss + return (x * x) # Driver Function -n = 5 +n = int(input("Enter a number: ")) print(sumOfSeries(n)) + + +#SOURCE +''' +THIS CODE IS TO FIND SUM OF CUBES OF FIRST n NATURAL NUMBERS. Formula: + +∑ k³ = [ n(n + 1) / 2 ]² (for k = 1 to n) +ex: +1³ + 2³ + ... + n³ = (n(n + 1) / 2)² + +'''