Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

#1.Program to find the largest among 3 numbers (if...elif...else...

)
print("To find the largest among 3 numbers")
print("*****************************")
num1=float(input("Enter the 1st number: "))
num2=float(input("Enter the 2nd number: "))
num3=float(input("Enter the 3rd number: "))
print('Numbers Entered Are')
print(" Number1: ",num1)
print(" Number2: ",num2)
print(" Number13: ",num3)
if((num1>num2) and (num1>num3)):
largest = num1
elif((num2>num1)and (num2>num3)):
largest = num2
else:
largest = num3
print("The largest num is:",largest)

-----------------------------------------------------------------
OUTPUT

To find the largest among 3 numbers


*****************************
Enter the 1st number: 21
Enter the 2nd number: 67
Enter the 3rd number: 44
Numbers Entered Are
Number1: 21.0
Number2: 67.0
Number13: 44.0
The largest num is: 67.0
------------------------------------------------------------
#2.Program to find whether the given is prime number or not (if...else...)
print("To find whether the given is prime number or not")
print("****************************************")
num=int(input("Enter the Number:"))
print("you have Entered ",num)
if num>1:
for i in range(1,num):
if(num%i)==0:
f=0
break
else:
f=1
if(f==0):
print(num,"is not a Prime Number")
else:
print(num,"is a Prime Number")
else:
print(num,"is not a Integer or a Positive Number")

-----------------------------------------------------------------
OUTPUT:

To find whether the given is prime number or not


****************************************
Enter the Number:7
you have Entered 7
7 is a Prime Number
>>>
To find whether the given is prime number or not
****************************************
Enter the Number:8
you have Entered 8
8 is not a Prime Number
>>>
-------------------------------------------------------------------------
#3.Program to find whether the given year is leap or not (Nested if...)
print("To find whether the given year is leap or not")
print("************************************")
year=int(input("Enter the year....:"))
if(year%100==0):
if(year%400==0):
print("Given",year," is a Leap year...")
else:
print("Given",year,"is not a Leap year")
elif(year%4==0):
print("Given",year," is a Leap year...")
else:
print("Given",year,"is not a Leap year")

OUTPUT

To find whether the given year is leap or not


************************************
Enter the year....:1900
Given 1900 is not a Leap year

To find whether the given year is leap or not


************************************
Enter the year....:2022
Given 2022 is not a Leap year

To find whether the given year is leap or not


************************************
Enter the year....:2024
Given 2024 is a Leap year...
-----------------------------------------------------------------------------
#4. Program using switch statement to display Sunday to Saturday
def switch(num):
dict={
1: 'Sunday',
2: 'Monday',
3: 'Tuesday',
4: 'Wednesday',
5: 'Thursday',
6: 'Friday',
7: 'Saturday'
}
return dict.get(num, 'Invalid Day')
num= int(input("Enter the Option"))
print(' The number is:', num, 'and the day is:',switch(num))

OUTPUT
Enter the Option2
The number is: 2 and the day is: Monday
>>>
Enter the Option5
The number is: 5 and the day is: Thursday
-------------------------------------------------------------------------------
#5. To check whether a given is a Palindrome using while statement
print("Find the given number is Palindrome")
n=int(input("Enter the number"))
sum=0
a=n
while(n>0):
m=n%10
sum=sum*10+m
n=n//10
if(sum==a):
print("The given number is Palindrome")
else:
print("The given number is not Palindrome")

OUTPUT:

Find the given number is Palindrome


Enter the number121
The given number is Palindrome
>>>
Enter the number125
The given number is not Palindrome

You might also like