Opening Hours :7AM to 9PM
if(condition): .... .... ....
'if else' is a keyword in python language .Which is used to execute one block of statements between two blocks
Syntax:
if(condition): .... .... else: .... ....In the above syntax 'if' condition is true the statements of 'if' block is execute.'if' the condition is false the statements of 'else' block is execute.
def myfun(): x=int(input("Enter x value")) if(x%2==0): print("Even") else: print("Odd") if __name__=="__main__": myfun()
def myfun(): x=int(input("Enter x value")) y=int(input("Enter y value")) if(x>y): print("x is max") else: print("y is max") if __name__=="__main__": myfun()
if(condition): ... ... elif(condition): ... ... elif(condition): ... ... elif(condition): ... ... .. .. .. .. else: ... ..
def myfun(): age=int(input("Enter age value")) if(age>0 and age<=12): print("Child age") elif(age>12 and age<=19): print("teen age") elif(age>19 and age<=40): print("younger age") elif(age>40 and age<=80): print("old age") elif(age>80 and age<=100): print("too old age") elif(age>100): print("invalid age") else: print("negative age") if __name__=="__main__": myfun()
if(condition): if(condition): ... ... else: .... ... else: .... ....
def myfun(): x=int(input("Enter x value")) if(x>0): if(x%2==0): print("Even Number") else: print("Odd Number") else: print("Pls enter positive number") if __name__=="__main__": myfun()
switcher ={ lable1: value, lable2: value, lable3: value, .. .. } print(switcher.get(value,"default value"))
def myfun(): p=(input("Enter character value")) switcher={ 'a':"Vowel", 'e':"Vowel", 'i':"Vowel", 'o':"Vowel", 'u':"Vowel", } print(switcher.get(p,"consonant")) if __name__=="__main__": myfun()
Check the given number is valid or invalid(value must between 20 and 30)
def myfun(): x=int(input("Enter x value")) if(x>=20 and x<=30): print("Valid Number") else: print("InValid Number") if __name__=="__main__": myfun()
Check the given number is valid or invalid(value must divisible by 2 and 3)
def myfun(): x=int(input("Enter x value")) if(x%2==0 and x%3==0): print("Valid Number") else: print("InValid Number") if __name__=="__main__": myfun()
Check the given number is valid or invalid(value must divisible by 2 and 3 not 4)
def myfun(): x=int(input("Enter x value")) if(x%2==0 and x%3==0 and x%!=0): print("Valid Number") else: print("InValid Number") if __name__=="__main__": myfun()
Check the given character is vowel or consonant
def myfun(): ch=input("Enter ch value") if(ch=='a' or ch=='e or ch=='i' or ch=='o' or ch=='u' or ch=='A' or ch=='E' or ch=='I' or ch=='O' or ch=='U'): print("Vowel") else: print("Consonant") if __name__=="__main__": myfun()
Check the given character is Small Letter or Not
def myfun(): ch=input("Enter ch value") if(ch>='a' and ch<='z'): print("Small Letter") else: print("Not a Small Letter") if __name__=="__main__": myfun()