Python Programming
Python Programming
Output
Output
Generate the following patterns using nested loop.
Pattern-1 Pattern-2 Pattern-3
* 12345 A
** 1234 AB
*** 123 ABC
**** 12 ABCD
***** 1 ABCDE
Code
Pattern 1
for i in range(1,6):
for j in range(i):
print('*',end='')
print('')
Pattern 2
for i in range(5,0,-1):
for j in range(1,i+1):
print(j,end=' ')
print()
Pattern 3-i
n=6
for i in range(n) :
t = 65
for j in range(i + 1) :
print(chr(t), end = ' ')
t += 1
print()
Output
1-x+x^2-x^3+x^4-…x^n
Code
print("Following series: 1-x+x^2-x^3+x^4-…x^n")
x=int(input("Enter value of x: "))
n=int(input("Enter value of n: "))
s=0
j=1
for i in range (n+1):
j=(-1)**i
k=j*(x**i)
s=s+k
print("Sum of the series: 1-x+x^2-x^3+x^4-…x^n")
print("with x:",x,"and n:",n,"is=",s)
Output
x+x^2/2-x^3/3+x^4/4-…x^n/n
Code
n=int(input("Enter the number of terms:"))
x=int(input("Enter the value of x:"))
sum1=1
for i in range(2,n+1):
sum1=sum1+((x**i)/i)
print("The sum of series is",round(sum1,2))
Output
x+x^2/2!-x^3/3!+x^4/4!-…x^n/n!
Code
x = int(input("Enter the value of x: "))
sum = 0
m=1
for i in range(1, 7) :
fact = 1
for j in range(1, i+1) :
fact *= j
term = x ** i / fact
sum += term * m
m = m * -1
print("Sum =", sum)
Output
Output