Python if else and if elif Loop

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

Program 1

# print word of number 

# n=int(input("Enter a number"))
# if(n==1):
#     print("One") 
# if(n==2):
#     print("Two") 
# if(n==3):
#     print("Three") 
# if(n==4):
#     print("Four") 
# if(n==5):
#     print("Five") 
# if(n>5 or n<1):
#     print("Invalid number")    

# Program for Driver selection

# name=input("Enter your name")
# age=int(input("Enter your age"))
# ms=input("Enter Merrital Status")
# if(name=="Rajesh"):
#     if(age>18 and age<50):
#         if(ms=='m'):
#             print("You are Selected.....")

# Program for Number even or odd        
# n=int(input("Enter a number"))
# if(n%2==0):
#     print("Number is even")
# else:
#      print("Number is odd")   

# Program for +ive or -ive     
# n=int(input("Enter a number"))
# if(n>=0):
#     print("Number is +ive")
# else:
#      print("Number is -ive")   


# Grater between three number
# a=int(input("Enter First Number"))
# b=int(input("Enter Second Number"))
# c=int(input("Enter Third Number"))
# if(a>b and a>c):
#     print("Grater number is %d " %(a))
# elif(b>c):
#     print("Grater number is %d " %(b))
# else:
#     print("Grater number is %d " %(c))    

# n=int(input("Enter a number"))
# if(n==1):
#     print("One")
# elif(n==2):
#     print("Two")
# elif(n==3):
#     print("Three")
# elif(n==4):
#     print("Four")
# elif(n==5):
#     print("Five")
# else:
#     print("Invalid number")
print("\n---------------Menu------------------")
print("1.Max \n2.Min \n 3.Swap")
print("\n---------------------------------------")
choice=int(input("Enter your choice"))
if(choice==1):
    a=int(input("Enter first Number"))
    b=int(input("Enter second Number"))
    print(max(a,b))

elif(choice==2):
    a=int(input("Enter first Number"))
    b=int(input("Enter second Number"))
    print(min(a,b))

elif(choice==3):
   a=int(input("Enter first Number"))
   b=int(input("Enter second Number"))
   print("Before Swaping %d %d "%(a,b))
   a,b=b,a     
   print("After Swaping %d %d "%(a,b))

else:
    print("Invalid choice")








    



 

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *