Class 11 Programs
- 1.Input a welcome message and display it
- 2.Input two numbers and display the larger/smaller number
- 3.Input three numbers and display the largest / smallest number
- 4.Enter two integers and perform all arithmetic operations
- 5.Generate patterns using nested loop
- 6.Input x and n, print sum of series
- 7.Check perfect number, Armstrong number or palindrome
- 8.Check if number is prime or composite
- 9.Display Fibonacci series terms
- 10.Compute GCD and LCM of two integers
- 11.Count vowels, consonants, uppercase, lowercase in string
- 12.Check palindrome string and convert case
- 13.Find largest/smallest number in list/tuple
- 14.Swap elements at even and odd locations
- 15.Search element in list/tuple
- 16.Find smallest and largest number from list
- 17.Dictionary with student marks above 75
- 18.Menu-driven student dictionary program
- 19.Choose 4 random lucky winners from 100 customers
- 20.String module operations menu
- 21.Friends phone directory dictionary operations
Series Types
- • Geometric Series (1 + x + x² + ...)
- • Alternating Series (1 - x + x² - ...)
- • Rational Series (x - x²/2 + x³/3 - ...)
- • Factorial Series (x - x²/2! + x³/3! - ...)
Key Concepts
- • Loop structures and iterations
- • Mathematical operations (**)
- • Conditional statements (if-else)
- • Modulo operator for alternating signs
- • Math module and factorial function
Input x and n, Print Sum of Series
AIM
To write Python programs to input the value of x and n and print the sum of different mathematical series.
ALGORITHM
- Start
- Input the value of x (base) and n (number of terms)
- Initialize sum variable according to the series type
- Use a loop to calculate each term of the series
- Add or subtract terms based on the series pattern
- Display the final sum
- Stop
PROGRAM
1. Series: 1 + x + x² + x³ + ... + xⁿ
# Series 1: 1 + x + x^2 + x^3 + ... + x^n
x = float(input('Enter value of x: '))
n = int(input('Enter value of n: '))
s = 0
for i in range(n + 1):
s += x**i
print('Sum of the series:', s)2. Series: 1 - x + x² - x³ + ... ± xⁿ
# Series 2: 1 - x + x^2 - x^3 + ... +/- x^n
x = float(input('Enter value of x: '))
n = int(input('Enter value of n: '))
s = 1
for i in range(1, n+1):
if i%2 == 0:
s = s + x**i
else:
s = s - x**i
print('Sum of the series:', s)3. Series: x - x²/2 + x³/3 - x⁴/4 + ...
# Series 3: x - x^2/2 + x^3/3 - x^4/4 + ...
x = float(input('Enter value of x: '))
n = int(input('Enter value of n: '))
sum = x
for i in range(2, n+1):
if (i%2 == 0):
sum -= (x**i)/i
else:
sum += (x**i)/i
print('Sum is:', sum)4. Series: x - x²/2! + x³/3! - x⁴/4! + ...
# Series 4: x - x^2/2! + x^3/3! - x^4/4! + ...
import math
x = float(input('Enter value of x: '))
n = int(input('Enter value of n: '))
sum = x
for i in range(2, n+1):
if (i%2 == 0):
sum = sum + ((x**i)/math.factorial(i))
else:
sum = sum - ((x**i)/math.factorial(i))
print('Sum is:', sum)OUTPUT
Series 1 Output:
Enter value of x: 2
Enter value of n: 4
Sum of the series: 31.0
Series 2 Output:
Enter value of x: 2
Enter value of n: 4
Sum of the series: 11.0
Series 3 Output:
Enter value of x: 2
Enter value of n: 4
Sum is: 0.6666666666666667
Series 4 Output:
Enter value of x: 2
Enter value of n: 4
Sum is: 1.4666666666666666
CONCLUSION
Thus, the given program was successfully executed and the output was verified as per the expected result.
VIVA QUESTIONS
What is the purpose of these series programs?
These programs calculate the sum of different mathematical series like geometric series, alternating series, and factorial-based series which are commonly used in mathematics and engineering.
What is the difference between Series 1 and Series 2?
Series 1 is a simple geometric series where all terms are positive. Series 2 is an alternating series where terms alternate between positive and negative based on whether the power is even or odd.
Why do we use math.factorial() in Series 4?
Series 4 involves factorial terms in the denominator (2!, 3!, 4!, etc.). The math.factorial() function calculates the factorial of a number efficiently.
What happens if we input negative values for x?
Negative values for x are valid and will produce different results. For alternating series, negative x values can affect the sign pattern of the terms.
How does the modulo operator (%) work in these programs?
The modulo operator (%) returns the remainder after division. We use i%2 to check if a number is even (remainder 0) or odd (remainder 1) to determine the sign of terms in alternating series.
What is the mathematical significance of Series 4?
Series 4 represents the Taylor series expansion of sin(x) or cos(x) functions, which are fundamental in calculus and used to approximate trigonometric functions.
Why do we initialize 'sum' differently in different series?
The initialization depends on the first term of each series. Series 1 and 2 start with 1, while Series 3 and 4 start with x, so we initialize accordingly.
What would happen if we input a very large value for n?
For large n values, the computation time increases, and for Series 4, factorial values become very large, which might cause overflow errors or precision issues in floating-point calculations.
Related Resources
- Pattern Generation Program
- Fibonacci Series Program
- Number Checks Program
- Flow of Control Theory
- Python Fundamentals
- Mathematical Series Tutorial
- Python Math Module Documentation
- Series and Sequences MCQs
Mathematical Concepts
- • Geometric progression and series
- • Alternating series convergence
- • Taylor series expansions
- • Factorial calculations
- • Power functions and exponents
Programming Tips
- • Use appropriate data types (float/int)
- • Handle large factorial values carefully
- • Test with different x and n values
- • Understand alternating sign patterns
- • Import math module for factorial
Need Help?
Join our tuition classes for detailed explanation of mathematical series and programming concepts.
Register for Classes →