Sharpen Your Skills: Programming Languages Practice Q&A

Programming practice questions

Python Program - if else

 
1

Question- Write a Python Program for Check whether an alphabet is vowel or consonant using if..else statement.



Answer- ch=input("Enter any character form A to Z or a to z")
if(ch=='A' or ch=='a' or ch=='E' or ch=='e' or ch=='I' or ch=='i' or ch=='O' or ch=='o' or ch=='U' or ch=='u'):
                                                                                           print("Enter Character is Vowel ");
else:
      print("Enter Character is Consonant ");
  


2

Question- Write a Python program for checking enter number is even or odd.



Answer- num=int(input("Enter a number"))

if(num%2==0):
       print("Number is Even ",num)
else:
      print("Number is Odd ",num)
3

Question- Write a Python program for checking enter number is Positive or Negative.



Answer-
num=int(input("Enter a number"))

if(num>=0):
      print("Number is Positive ",num)
else:
      print("Number is Negative ",num)
4

Question- Write a Python program to take two number from user and check who is max.



Answer-
num1=int(input("Enter a number"))
num2=int(input("Enter 2nd number"))
if(num1>num2):
       print(" 1st Number is Max ",num1)
else:
      print(" 2nd Number is Max ",num2)
5

Question- Write a Python program to take input age of person and check he is eligible for marriage or not.



Answer-
age=int(input("Enter age of person."))

if(age>=21):
      print("Person is eligible for marriage ",age)
else:
    print("Person is not eligible for marriage ",age)
6

Question- Write a program to take input age of male or Female and check he/she is eligible for marriage or not.



Answer-
gen=input("Enter gender of human like male or female")

age=int(input("Enter Age"))

if(gen=="male"):
         if(age>=21):
                print("Hello Man, you are Eligible for Marriage  ",age);

         else:
            print("Hello Man, Not Eligible for Marriage ",age);
else:
     if(age>=18):
             print("Hello Lady, you are Eligible for Marriage  ",age);

     else:
        print("Hello Lady, Not Eligible for Marriage ",age);