A014 Python Practical 1
A014 Python Practical 1
Program A
Aim:-Create a program that asks the user to enter their name and
their age. Print out a message addressed to them that tells them
the year that they will turn 100 years old.
Code:-
#Practical A1 implementation
print("Practical A1: Program to display in which calendar year the person
will turn 100")
name=input("Enter your name:")
age=int(input("Enter your age:"))
year=str((2021-age)+100)
print(name+" will be 100 years old in the year "+year)
Output:-
Program B
Aim:- Enter the number from the user and depending on whether
the number is even or odd, print out an appropriate message to
the user.
Code:-
#Practical B1 implementation
print("Practical B1: Program to display whether a number is odd or even ")
n=age=int(input("Enter a number:"))
if(n%2==0):
print("The number "+str(n)+" is an even number")
else:
print("The number "+str(n)+" is a odd number")
Output:-
Program C
Aim:- Write a program to generate the Fibonacci series.
Code:-
#Practical C1 implementation
print("Practical C1: Program to display the fibonnaci series")
n=int(input("Enter the number of values:"))
a,b=0,1
i=1
while i<=n:
print(a,end="\n")
a,b=b,a+b
i=i+1
Output:-
Program D
Aim:- Write a function that reverses the user defined value and check
whether it is palindrome or not.
Code:-
#Practical 1d implementation
def palindrome(n):
n1=n
rev=0
i=0
while (n1!=0):
r=int(n1%10)
rev=rev*10+r
n1=int(n1/10)
print("The reverse of the number is "+str(rev))
if (rev == n):
print("The number is Palindrome")
else:
print ("The number is not a Palindrome")
Program E
Aim: -Write a function to check the input value is Armstrong
Code:-
#Practical E1 implementation
def armstrong(n):
f=n
s=0
while (f!=0):
a=int(f%10)
f=(f/10)
s=s+(a**3)
y=s
if(n==y):
print('%d is an armstrong number'%n)
else:
print('%d is not an armstrong number'%n)
print("Practical E1: Program to display the whether armstrong or
not") n=int(input("Enter any Number "))
armstrong(n)
Output:-
Program F
Aim:- Write a recursive function to print the factorial for a given
number.
Code:-
#Practical F1 implementation
def fact(n):
f=1
i=1
for i in range(i,n+1):
f=f*i
print("The factorial of the number is ",f)