~1 min read • Updated Oct 12, 2025
Program Overview
This Python program reads two integers a and b from the user.
It calculates the sum of a mathematical series between those two numbers.
In this version, we assume the series is simply the sum of all integers from a to b, but you can easily modify the formula to fit any custom series.
Python Code:
def series_sum(a: int, b: int) -> int:
total = 0
for i in range(a, b + 1):
total += i # Replace this line with any custom series formula
return total
# Read inputs from user
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
result = series_sum(a, b)
print(f"The sum of the series from {a} to {b} is: {result}")
Sample Output (input: a = 9, b = 11):
The sum of the series from 9 to 11 is: 30
Step-by-Step Explanation:
- The user enters two numbers
- The program uses a loop to calculate the sum of values between them
- You can replace the formula inside the loop to compute factorials, powers, or any other series
- The final result is printed
Written & researched by Dr. Shahin Siami