0% found this document useful (0 votes)
104 views

A014 Python Practical 1

The document contains summaries of 6 programs: 1) A program that asks for a user's name and age and prints the year they will turn 100. 2) A program that takes a number as input and prints if it is even or odd. 3) A program that generates the Fibonacci series up to a number input by the user. 4) A program that reverses a number and checks if it is a palindrome. 5) A program that checks if a number is an Armstrong number. 6) A program that calculates and prints the factorial of a number using a recursive function.

Uploaded by

Nandan Gowda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

A014 Python Practical 1

The document contains summaries of 6 programs: 1) A program that asks for a user's name and age and prints the year they will turn 100. 2) A program that takes a number as input and prints if it is even or odd. 3) A program that generates the Fibonacci series up to a number input by the user. 4) A program that reverses a number and checks if it is a palindrome. 5) A program that checks if a number is an Armstrong number. 6) A program that calculates and prints the factorial of a number using a recursive function.

Uploaded by

Nandan Gowda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

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")

print("Practical 1d: Program to display the reverse of a number")


n=int(input("Enter Number to check the Reverse "))
palindrome(n)
Output:-

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)

print("Practical 1f: Program to display the factorial of a number")


n=int(input("Enter a number:"))
fact(n)
Output:-

You might also like