Program to input the value of x and n and print the sum of series 1+x+x^2+x^3+x^4..x^n | Practical
In this video, I have covered up the practical 5 of CBSE Class 11 Computer Science with Python.
Write a program to input the value of x and n and print the sum of the following series: 1+x+x2+x3+x4+ ............xn.
I have described 3 different methods that can be used for the problem with their programming codes.
Method 1:
#Write a program to input the value of x and n and print the sum of the following series:
#1+x+x^2+x^3+x^4+ ............x^n
print(" Write a program to input the value of x and n and print the sum of the \n")
print(" following series: 1+x+x^2+x^3+x^4+ ............x^n \n")
x = int(input("Enter value of x:"))
n=int(input("Enter value of n:"))
s=0
for i in range(n+1):
k=x**i
s=s+k
print(" Sum of the series: 1+x+x^2+x^3+x^4+ ............x^n \n")
print(" with x:",x,"and n:",n,"is=",s)
Method 2:
#Write a program to input the value of x and n and print the sum of the following series:
#1+x+x^2+x^3+x^4+ ............x^n
print(" Write a program to input the value of x and n and print the sum of the \n")
print(" following series: 1+x+x^2+x^3+x^4+ ............x^n \n")
x = int(input("Enter value of x:"))
n=int(input("Enter value of n:"))
s=1
k=1
for i in range(n):
for j in range(i):
k=k*x
s=s+k
print(" Sum of the series: 1+x+x^2+x^3+x^4+ ............x^n \n")
print(" with x:",x,"and n:",n,"is=",s)
Method 3:
#Write a program to input the value of x and n and print the sum of the following series:
#1+x+x^2+x^3+x^4+ ............x^n
import math
print(" Write a program to input the value of x and n and print the sum of the \n")
print(" following series: 1+x+x^2+x^3+x^4+ ............x^n \n")
x = int(input("Enter value of x:"))
n=int(input("Enter value of n:"))
s=0
for i in range(n+1):
k=math.pow(x,i)
s+=k
print(" Sum of the series: 1+x+x^2+x^3+x^4+ ............x^n \n")
print(" with x:",x,"and n:",n,"is=",s)
To learn python full course watch: https://www.youtube.com/watch?v=-eZ9aGK4NmY&list=PLuND5JsayY-xzEYTExVVsHSnV3RyU7_Og
To learn Class XI Computer Science: https://www.youtube.com/watch?v=6QVBMuWIBrk&list=PLuND5JsayY-ypqFFFqQyD_H5y5MdIflMc
fb page : https://www.facebook.com/computerguruhub/
Author on fb: https://www.facebook.com/sknager
Telegram Channel: https://t.me/computerguruhub
Telegram Group: https://t.me/computerguruhub1
if you want video on any particular topic you can comment or contact.
#computerscience #cbse #computerscienceclass11 #python #class11computerscience #pythonprogramming #cbsepythonclass11 #pythonclass11 #class11 #class11pythoninhindi #pythonclass12 #class11python #pythonforclass11 #pythontutorial #advantagesofpython #csforclass11 #codipymohit #pythonpracticalprogramming #ipforclass11 #practical #class11pythonchapter1 #pythontutorialforbeginners #cbsepythonboardexampapers #class12pythoninhindi #completepythoncourse #cs #xi #cbseclass11computerscience #computerscienceclass11cbse #sumitaaroraclass11 #pythoninhindi #class11pythoncbse #computerscienceforclass11 #pythonforbeginners #pythonclass11cbse #classxi
#sumitkumarnager #computerguruhub
Видео Program to input the value of x and n and print the sum of series 1+x+x^2+x^3+x^4..x^n | Practical автора Создание умных помощников
Видео Program to input the value of x and n and print the sum of series 1+x+x^2+x^3+x^4..x^n | Practical автора Создание умных помощников
Информация
2 декабря 2023 г. 22:24:49
00:14:34
Похожие видео