23 - Write a program in Python to print all Armstrong numbers from 0 to 10000.
for n in range(0,10001):
sum=0
k=n
while n>0:
r=n%10
n=n//10
sum=sum+r*r*r
if(sum==k):
print(k,end=" ")
for n in range(0,10001):
sum=0
k=n
while n>0:
r=n%10
n=n//10
sum=sum+r*r*r
if(sum==k):
print(k,end=" ")
n=int(input("Enter a number: "))
sum=0
k=n
while n>0:
r=n%10
n=n//10
sum=sum+r*r*r
if(sum==k):
print(k, "is a armstrong number")
else:
print(k, "is not a armstrong number")
n=int(input("Enter a number: "))
product=1
while n>0:
r=n%10
n=n//10
product=product*r
print("Multiplication of digits=",product)
n=int(input("Enter a number: "))
sum=0
while n>0:
r=n%10
n=n//10
sum=sum+r
print("Sum of digits=",sum)
a=0
b=1
n=int(input("Enter the number of terms to be printed for fibonacci Series: "))
print(a, b,end=' ')
for i in range(1,n-1):
c=a+b
print(c,end=' ')
a=b
b=c
Output:
Enter the number of terms to be printed for fibonacci Series: 10
0 1 1 2 3 5 8 13 21 34
1
234
56789
10111213141516
p=1
a=5
k=2
n=3
for i in range(1,5):
for s in range(1,a):
print(end=' ')
for j in range(p,k):
print(j,end='')
print()
a=a-1
p=j+1
k=k+n
n=n+2
Output:
1
234
56789
10111213141516
ABCDEFEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
y=71
sp=2
for i in range(1,8):
x=65
while(x<y):
print(chr(x),end='')
x=x+1
if i==1:
x=x-2
else:
x=x-1
for s in range(1,sp):
print(end=' ')
sp=sp+2
while(x>64):
print(chr(x),end='')
x=x-1
print()
y=y-1
Output:
ABCDEFEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
1
123
12345
1234567
123456789
sp=5
k=2
for i in range(1,6):
for s in range(1,sp):
print(end=' ')
for j in range(1,k):
print(j,end='')
print()
sp=sp-1
k=k+2
1
123
12345
1234567
123456789
*
**
***
****
*****
for i in range(1,6):
for j in range(1,i+1):
print("*",end='')
print()
*
**
***
****
*****
A
AB
ABC
ABCD
ABCDE
for i in range(1,6):
for j in range(1,i+1):
print(chr(j+64),end='')
print()
Output:
A
AB
ABC
ABCD
ABCDE