From cb3613319a7ddb1288ea73156ba253f8cfd359d8 Mon Sep 17 00:00:00 2001 From: DarkCoder Date: Sat, 5 Oct 2019 16:47:09 +0600 Subject: [PATCH 1/4] Added a python script for finding sum of arithmetic series --- maths/sum_of_arithmetic_series.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 maths/sum_of_arithmetic_series.py diff --git a/maths/sum_of_arithmetic_series.py b/maths/sum_of_arithmetic_series.py new file mode 100644 index 000000000000..1c4bed8d8bb4 --- /dev/null +++ b/maths/sum_of_arithmetic_series.py @@ -0,0 +1,9 @@ +def sumOfSeries(a, d, n): + sum = (n / 2) * (2 * a (n - 1) * d) + return sum + +given_a = int(input("Enter the first value of the series: ")) +given_d = int(input("Enter the difference of each term: ")) +given_n = int(input("Enter the number of terms: ")) + +print(sumOfSeries(given_a, given_d, given_n)) \ No newline at end of file From 9ed2fa3c77d82e2b865f9c0ab81f2c459c67cd52 Mon Sep 17 00:00:00 2001 From: DarkCoder Date: Sat, 5 Oct 2019 18:22:47 +0600 Subject: [PATCH 2/4] Added some linting --- maths/sum_of_arithmetic_series.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) mode change 100644 => 100755 maths/sum_of_arithmetic_series.py diff --git a/maths/sum_of_arithmetic_series.py b/maths/sum_of_arithmetic_series.py old mode 100644 new mode 100755 index 1c4bed8d8bb4..6253d136a36d --- a/maths/sum_of_arithmetic_series.py +++ b/maths/sum_of_arithmetic_series.py @@ -1,9 +1,12 @@ +# DarkCoder def sumOfSeries(a, d, n): - sum = (n / 2) * (2 * a (n - 1) * d) - return sum + sum = ((n / 2) * (2 * a * (n - 1) * d)) # formula for sum of series + print(sum) -given_a = int(input("Enter the first value of the series: ")) -given_d = int(input("Enter the difference of each term: ")) -given_n = int(input("Enter the number of terms: ")) -print(sumOfSeries(given_a, given_d, given_n)) \ No newline at end of file +def main(): + sumOfSeries(3, 4, 100) + + +if __name__ == "__main__": + main() From b5b3126dfa839f6c08a8ad62bbecb58fc28d3627 Mon Sep 17 00:00:00 2001 From: DarkCoder Date: Sat, 5 Oct 2019 20:25:07 +0600 Subject: [PATCH 3/4] Resolved comments --- maths/sum_of_arithmetic_series.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/maths/sum_of_arithmetic_series.py b/maths/sum_of_arithmetic_series.py index 6253d136a36d..45d45a5f28df 100755 --- a/maths/sum_of_arithmetic_series.py +++ b/maths/sum_of_arithmetic_series.py @@ -1,12 +1,21 @@ # DarkCoder -def sumOfSeries(a, d, n): - sum = ((n / 2) * (2 * a * (n - 1) * d)) # formula for sum of series - print(sum) +def sum_of_series(first_term, common_difference, number_of_terms): + """ + Find the sum of n terms in an arithmetic progression. + + >>> sum_of_series(1, 1, 10) + 55.0 + >>> sum_of_series(1, 10, 100) + 49600.0 + """ + sum = ((number_of_terms / 2) * (2 * first_term + (number_of_terms - 1) * common_difference)) # formula for sum of series + return sum def main(): - sumOfSeries(3, 4, 100) + print(sum_of_series(1, 1, 10)) if __name__ == "__main__": - main() + import doctest + doctest.testmod() From 6936c49547efa47402c9be3527c88c7e65a9ed41 Mon Sep 17 00:00:00 2001 From: DarkCoder Date: Sun, 6 Oct 2019 02:27:26 +0600 Subject: [PATCH 4/4] Fixed flake8 test --- maths/sum_of_arithmetic_series.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/maths/sum_of_arithmetic_series.py b/maths/sum_of_arithmetic_series.py index 45d45a5f28df..f7ea5dc84cb8 100755 --- a/maths/sum_of_arithmetic_series.py +++ b/maths/sum_of_arithmetic_series.py @@ -1,5 +1,5 @@ # DarkCoder -def sum_of_series(first_term, common_difference, number_of_terms): +def sum_of_series(first_term, common_diff, num_of_terms): """ Find the sum of n terms in an arithmetic progression. @@ -8,7 +8,8 @@ def sum_of_series(first_term, common_difference, number_of_terms): >>> sum_of_series(1, 10, 100) 49600.0 """ - sum = ((number_of_terms / 2) * (2 * first_term + (number_of_terms - 1) * common_difference)) # formula for sum of series + sum = ((num_of_terms/2)*(2*first_term+(num_of_terms-1)*common_diff)) + # formula for sum of series return sum