next


Python Online Compiler

ElseIF Condition
Conditional

def Rain():
    name=input("Enter Name")
    location=input("Enter Location")
    gender=input("Enter Gender")
    age=int(input("Enter Age"))
    print("Your Name is ",name)
    print("Your Location is ",location)
    print("Your Gender is ",gender)
    
    if(age>0 and age<=12):
        print("You Are Child Age")
    elif(age>12 and age<=19):
        print("You Are Teen Age")
    elif(age>19 and age<=40):
        print("You Are  Younger Age")
    elif(age>40 and age<=80):
        print("You Are  Old Age")
    elif(age>80 and age<=100):
        print("You Are Too Old Age")
    else:
        print("Invalid Age")
        
   

#function Calling
Rain()
OUTPUT: Enter NameSateesh Enter LocationChennai Enter GenderM Enter Age24 Your Name is Sateesh Your Location is Chennai Your Gender is M You Are Younger Age

Nested IF Condition

def Rain():
    name=input("Enter Name")
    location=input("Enter Location")
    gender=input("Enter Gender")
    age=int(input("Enter Age"))
    if(age>0):
        print("Your Name is ",name)
        print("Your Location is ",location)
        print("Your Gender is ",gender)
    
        if(age>0 and age<=12):
            print("You Are Child Age")
        elif(age>12 and age<=19):
            print("You Are Teen Age")
        elif(age>19 and age<=40):
            print("You Are  Younger Age")
        elif(age>40 and age<=80):
            print("You Are  Old Age")
        elif(age>80 and age<=100):
            print("You Are Too Old Age")
        else:
            print("Invalid Age")
    else:
        print("Age Must BePositive Number")
        
   

#function Calling
Rain()

OUTPUT: Enter NameSateesh Enter LocationChennai Enter GenderM Enter Age24 Your Name is Sateesh Your Location is Chennai Your Gender is M You Are Younger Age

ODD or EVEN number Using Switch

def Rain(argument):
   argument=argument%2
   switcher = { 
        0: "Even Number", 
        1: "Odd Numbar", 
         
    }
   return switcher.get(argument, "nothing") 

#function Calling
if __name__ == "__main__": 
    argument=24
    print (Rain(argument) )


OUTPUT: Even Number

Vowel Consonant Program Using Switch

def Rain(argument):
   
   switcher = { 
        'a': "Vowel", 
        'e': "Vowel",
        'i': "Vowel",
        'o': "Vowel",
        'u': "Vowel",
        
         
    }
   return switcher.get(argument, "Consonant") 

#function Calling
if __name__ == "__main__": 
    argument='e'
    print (Rain(argument) )
OUTPUT: Vowel

Display 1 to 10 Values Using For Loop
For Loop

def Rain():
   
    for x in range(1,10,1):
        print(x)

#function Calling
Rain()

OUTPUT: 1 2 3 4 5 6 7 8 9 10

Display 1 to N Values Using For Loop

def Rain():
    n=int(input("Enter n Value"))
    for x in range(1,n,1):
        print(x)

#function Calling
Rain()
OUTPUT: Enter n Value10 1 2 3 4 5 6 7 8 9

Display A To Z Using For Loop

def Rain():
    n=input("Enter n Value")
    
    for x in range(65,ord(n),1):
        print(chr(x))

#function Calling
Rain()
OUTPUT: Enter n ValueS A B C D E F G H I J K L M N O P Q R

Factorial Number

def Rain():
    n=int(input("Enter n Value"))
    fact=1
    
    for x in range(1,n+1,1):
        fact=fact*x
    print(fact)

#function Calling
Rain()
OUTPUT: Enter n Value5 120

Factorial of N Numbers

def Rain():
    n=int(input("Enter n Value"))
    fact=1
    
    for x in range(1,n+1,1):
        fact=fact*x
        print(x," Factorial = ",fact)

#function Calling
Rain()
OUTPUT: Enter n Value5 1 Factorial = 1 2 Factorial = 2 3 Factorial = 6 4 Factorial = 24 5 Factorial = 120

Sum Of Natural Numbers
                      
def Rain():
    n=int(input("Enter n Value"))
    sum=0
    
    for x in range(1,n+1,1):
        sum=sum+x
    print(" Sum is = ",sum)

#function Calling
Rain()
OUTPUT: Enter n Value10 Sum is = 55

Sum Of Even Numbers

def Rain():
    n=int(input("Enter n Value"))
    sum=0
    
    for x in range(1,n+1,1):
        if(x%2==0):
            sum=sum+x
    print("Even Sum is = ",sum)

#function Calling
Rain()
OUTPUT: Enter n Value4 Even Sum is = 6

Sum of Odd Numbers

def Rain():
    n=int(input("Enter n Value"))
    sum=0
    
    for x in range(1,n+1,1):
        if(x%2!=0):
            sum=sum+x
    print("Even Sum is = ",sum)

#function Calling
Rain()
OUTPUT: Enter n Value4 Odd Sum is = 6

Sum Of Even Or Odd Numbers Based On The N value

def Rain():
    n=int(input("Enter n Value"))
    sum=0
    if(n%2==0):
        for x in range(1,n+1,1):
            if(x%2==0):
                sum=sum+x
    else:
        for x in range(1,n+1,1):
            if(x%2!=0):
                sum=sum+x
        
    print(" Sum is = ",sum)

#function Calling
Rain()
OUTPUT: Enter n Value6 Sum is = 12 Enter n Value5 Sum is = 9

Nested For Loop

def Rain():
    n=int(input("Enter n Value"))
    
    for x in range(1,n,1):
        for y in range(1,x,1):
            print("*",end=' ')
        print(end="\n")
    
   

#function Calling
Rain()

OUTPUT: Enter n Value9 * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Display 1 To 10 Using While Loop
While
                                
def Rain():
    n=int(input("Enter n Value"))
    x=1
    while(x<=n):
        print(x)
        x=x+1
    
#function Calling
Rain()

OUTPUT: Enter n Value10 1 2 3 4 5 6 7 8 9 10

Factorial Number Using While Loop
                            
def Rain():
    n=int(input("Enter n Value"))
    x=1
    fact=1
    while(x<=n):
        fact=fact*x
        x=x+1
    print(n," Factorial is ",fact)
    
#function Calling
Rain()
OUTPUT: Enter n Value5 5 Factorial is 120

Display Student Details(Age Must Be 20 To 30 Between)

def Rain():
    name=input("Enter Name")
    age=int(input("Enter Age "))
    
    while(age<20 or age>30):
          age=int(input("Enter Age Again"))
    print("Your name is", name)
    print("Your Age is ",age)
    
#function Calling
Rain()
OUTPUT: Enter NameSateesh Enter Age 12 Enter Age Again67 Enter Age Again24 Your name is Sateesh Your Age is 24

Display Valid or invalid Character (Character Must Be Upper Case Letter).

def Rain():
    n=input("Enter Characer Value")
    
    while(not(n>='A' and n<='Z')):
           n=input("Enter Characer  Again")
   
    print("Given Character is valid")
    
#function Calling
Rain()
OUTPUT: Enter Characer Valuef Enter Characer Againj Enter Characer Againr Enter Characer AgainG Given Character is valid

Continue Statement
UnConditional


def Rain():
    n=int(input("Enter n Value"))
    for x in range(1,n,1):
        if(x%2==0 and x%3==0):
            continue;
        print(x)
    
#function Calling
Rain()
OUTPUT: Enter n Value30 1 2 3 4 5 7 8 9 10 11 13 14 15 16 17 19 20 21 22 23 25 26 27 28 29

Break Statement
                                

def Rain():
    n=int(input("Enter n Value"))
    for x in range(1,n,1):
        if(x%2==0 and x%3==0):
            break;
        print(x)
    
#function Calling
Rain()
OUTPUT: Enter n Value30 1 2 3 4 5

Print The Ascii Values Of A to Z

def Rain():
    for x in range(65,65+26,1):
        print(chr(x)," = ",x)
    
#function Calling
Rain()
OUTPUT: A = 65 B = 66 C = 67 D = 68 E = 69 F = 70 G = 71 H = 72 I = 73 J = 74 K = 75 L = 76 M = 77 N = 78 O = 79 P = 80 Q = 81 R = 82 S = 83 T = 84 U = 85 V = 86 W = 87 X = 88 Y = 89 Z = 90

Print The ASCII Values Of a to z

def Rain():
    for x in range(97,97+26,1):
        print(chr(x)," = ",x)
    
#function Calling
Rain()
OUTPUT: a = 97 b = 98 c = 99 d = 100 e = 101 f = 102 g = 103 h = 104 i = 105 j = 106 k = 107 l = 108 m = 109 n = 110 o = 111 p = 112 q = 113 r = 114 s = 115 t = 116 u = 117 v = 118 w = 119 x = 120 y = 121 z = 122