Doc3
Doc3
n=eval(input("Enter a number:"))
s=0
p=n
while p!=0:
r=p%10
p=p//10
s=s+(r*r*r)
if n==s:
print("The number is Armstrong")
else:
print("The number is not Armstrong")
Output:
Enter a number:153
The number is Armstrong.
Enter a number:145
The number is not Armstrong.
Page no.:
Output:
Enter the number of rows:5
*
**
***
****
*****
Page no.:
Program:
r=eval(input("Enter a number:"))
m=r//2+1
for i in range(1,m+1):
for j in range(1,i+1):
print("*",end=" ")
print('')
for i in range(m+1,r+1):
for j in range(1,r-i+2):
print("*",end=" ")
print('')
Output:
Enter a number:7
*
**
***
****
***
**
*
Page no.:
def fib(n):
if n==1:
return 0
elif n==2:
return 1
else:
return fib(n-1)+fib(n-2)
n=eval(input("Enter the term:"))
f=1
for i in range(1,n+1):
f=fib(i)
print(f,end=" ")
Output:
Enter the term:10
0 1 1 2 3 5 8 13 21
Page no.:
Program:
def even_odd(n):
r=n%2
if r==0:
print("The number is Even")
else:
print("The number is Odd")
n=eval(input("Enter a number:"))
even_odd(n)
Output:
Enter a number:53
The number is Odd
Enter a number:86
The number is Even
Page no.:
def is_even(n):
r=n%2
if r==0:
return True
else:
return False
n=eval(input("Enter a number:"))
e=is_even(n)
if e==True:
print("The number is Even")
else:
print("The number is Odd")
Output:
Enter a number:69
The number is Odd
Enter a number:96
The number is Even
Page no.:
s='ABCDEF'
l=len(s)
s1=' '
for i in range(5,-1,-1):
s1=s1+s[i]
print("The reversed string is:",s1)
Output:
Program:
s='ABCDEF'
l=len(s)
s1=' '
for i in range(l):
s1=s[i]+s1
print(“The reversed string is:”,s1)
Output:
i,j=0,1
fib=int(input("Enter the term:"))
while(fib>0):
print(i,end=" ")
i=i+j
j=i-j
fib-=1
Output:
Program:
n=eval(input("Enter a number:"))
if n<0:
print("Invalid syntax:")
else:
f=1
for i in range(1,n+1):
f=f*i
print ("The factorial is:",f)
Output:
Enter a number:7
The factorial is: 5040
Page no.:
Program:
def fact(n):
if n==0:
return 1
else:
return n*fact(n-1)
n=eval(input("Enter the number:"))
print("The factorial of the number is:",fact(n))
Output:
def isPalindrome(str):
for i in range(0,int(len(str)/2)):
if str[i]!=str[len(str)-i-1]:
return False
return True
s=str(input("Enter the string: "))
pal=isPalindrome(s)
if pal:
print("The string is Palindrome")
else:
print("The string is Not Palindrome")
Output:
Output:
Program:
import math
def is_prime(y):
p=True
sq=int(math.sqrt(y))
for i in range(2,sq+1):
if y%i==0:
p=False
break
return p
r=eval(input("Enter the number:"))
if is_prime(r)==True:
print(f"{r} is prime.")
else:
print(f"{r} is not prime.")
Output:
Program:
Output:
Output:
Enter the number:456654
The number is Palindrome
Output:
Enter the number of rows:5
*****
****
***
**
*
Page no.:
1
12
123
1234
12345
Program:
Output:
Enter the number of rows:5
1
12
123
1234
12345