You are on page 1of 5

PROGRAM 1.

AIM: To write a program to input 3 numbers and print the greatest number using nested if
ALGORITHM:
Step 1 : Start the program
Step 2 : Get the values for the list using assignment statement
Step 3 : Compare first element with remaining elements
Step 4 : Stop the program.
PROGRAM:
a=float(input("Enter the first number: "))
b=float(input("Enter the second number: "))
c=float(input("Enter the third number: "))
if a>b:
if a>c:
print("First number :",a,"is greatest")
if b>a:
if b>c:
print("Second number :",b,"is greatest")
else:
print("Third number :",c,"is greatest")
OUTPUT:
Enter the first number4
Enter the second number2
Enter the third number2.1
First number : 4.0 is greatest

RESULT:
Thus the program to input 3 numbers and print the greatest number using nested if has been created and
executed successfully.
PROGRAM 2
AIM:To write a program to input percentage marks of a student and find the grade as per mark.

ALGORITHM:
Step 1 : Start the program
Step 2 : Get the value by input function.
Step 3 : Find the grade for given mark by using if-elif conditions as
follows
if a>=90:
print('The student has got an A grade')
elif a>=75 and a<90:
print('The student has got a B grade')
elif a>=60 and a<75:
print('The student has got a C grade')
else:
print('The student has got a D grade')
Step 4 : Display the output by finding the grade for given mark
Step 5 : Stop the program.
PROGRAM:
a=float(input('Enter the percentage marks:'))
if a>=90:
print('The student has got an A grade')
elif a>=75 and a<90:
print('The student has got a B grade')
elif a>=60 and a<75:
print('The student has got a C grade')
else:
print('The student has got a D grade')
OUTPUT:
Enter the percentage marks: 85
The student has got a B grade
RESULT:
Thus the program to input percentage marks of a student and find the grade as per mark has been created
and executed successfully.
PROGRAM 3:
AIM: To write a program to check a number is a prime number or not.
ALGORITHM:
Step 1 : Start the program
Step 2 : Get the number by input function.
Step 3 : Check the number as prime or not using for loop and if condition
as follows
for i in range(2,num//2+1):
if num%i==0:
Step 4 : If the above condition satisfied , then print not a prime number or
else print it is a prime number
Step 5 : Stop the program.
PROGRAM:
num=int(input('Enter the number:'))
for i in range(2,num//2+1):
if num%i==0:
print('It is not a prime number')
break
else:
print('It is a prime number')
OUTPUT:
Enter the number: 12
It is not a prime number
RESULT:
Thus the program to check a given number is a prime number or not has been created and executed
successfully.
PROGRAM: 4
AIM:To write a program to print whether a given character is an uppercase or a lowercase character
or a digit or any other character.
ALGORITHM:
Step 1 : Start the program
Step 2 : Get the character by input function.
Step 3 : Check the given character is an uppercase or a lowercase
character or a digit or any other character by using if conditions as
follows
if ch>='A' and ch<='Z':
print('You have entered an uppercase character.')
elif ch>='a' and ch<='z':
print('You have entered an lowercase character.')
elif ch>='0' and ch<='9':
print('You have entered a digit.')
else:
print('You have entered a special character.')
Step 4 : Print the result as per the satisfied condition.
Step 5 : Stop the program.
PROGRAM:
ch=input('Enter a single character:')
if ch>='A' and ch<='Z':
print('You have entered an uppercase character.')
elif ch>='a' and ch<='z':
print('You have entered a lowercase character.')
elif ch>='0' and ch<='9':
print('You have entered a digit.')
else:
print('You have entered a special character.')
OUTPUT:
Enter a single character: c
You have entered a lowercase character.
RESULT: Thus the program to print whether a given character is an uppercase or alowercase character or a
digit or any other character has been created and executed successfully.
PROGRAM 5:
AIM: To write a program to calculate the factorial of a number.
ALGORITHM:
Step 1 : Start the program
Step 2 : Get the number by input function.
Step 3 : Calculate the factorial of a given number using while condition as
follows
while a<=num:
fact*=a
a+=1
Step 4 : Print the factorial of a number once the while loop exists.
Step 5 : Stop the program.

PROGRAM:
num=int(input('Enter a number:'))
fact=1
a=1
while a<=num:
fact*=a
a+=1
print('The factorial of',num,'is',fact)
OUTPUT:
Enter a number: 5
The factorial of, 5 is 120

RESULT:
Thus the program to calculate the factorial of a number has been created and
executed successfully.

You might also like