Skip to main content

Python : Basic Funtion Programs


#Program to find Average of 2 number (CWH)

input ( " Enter first number : " )

input ( " Enter second number : " )
a = int ( a ) #For Converting it to int from str type
b = int ( b ) # other wise bellow opertaion did not work as it is string
avg ( a + b ) / 2
print ( " The average of a and b is " , avg )



# Program to write a latter and then change its name and date using replace()

 Application = '''Dear Name Sir

You are Selected in event of Date'''
Name=input("Input Name\t")
Date=input("Date\t")
Application = Application.replace("Name",Name)
Application = Application.replace("Date",Date)
print(Application)

Output:

Input Name Ani Date 21 Dear Ani Sir You are Selected in event of 21


 # Program to find Double Space in a String

find()

string ="This is a string which contain double   Space"
nods=string.find("  ")
print(nods)

# Program to find Double Space in a String
replace()

string ="This is a string which contain double Space"
nods=string.find("  ")
if (nods== -1):
    print("No Double Space found")
else:
    print("Double Space found at :", nods)
string=string.replace("  "," ")
print("\n")
print(string)





Popular posts from this blog

C++ : Calculator

  # include < iostream > using namespace std ; int main () {     int a , b ;     char o ;     float c ;     cout << " Enter Value of A \n " ;     cin >> a ;     cout << " Enter Value of B \n " ;     cin >> b ;     cout << " Enter Operation \n " << " + for Addition \n - for substration \n * for multiplication \n / for division \n " ;     cin >> o ;     switch ( o )     {         case ' + ' :       {            c = a + b ;             break ;       }       case ' - ' :       {           c = a - b ;           break ;       }       case ' / ' :       {         ...

C++ : Pointer Program

# include < iostream > using namespace std ; int main () {     int a = 4 ;     int * b =& a ;     // & is address of operator     cout << " Thr address of a is " << & a << endl ;     cout << " Thr address of a is " << b << endl ;     // * is value at dereference operator     cout << " Thr value of a is " << * b << endl ;           // Pointer to pointer     int ** c =& b ; cout << " The adress of b is " << & b << endl ;     cout << " The adress of b is " << c << endl ;     cout << " The value at address c is " << * c << endl ;     cout << " The value at address value_at (value_at( c )) is " << ** c << endl ;     } OUTPUT =>           Thr address of...

Python : Small Projects (CWH)

  # Project 1 : Snake, Water, Game OR Rock,Paper,Scissor import random def game ( comp , you ) :     if comp == you :         return 2     elif comp == " s " :         if you == " w " :             return 0         elif you == " g " :             return 1     elif comp == " w " :         if you == " g " :             return 0         elif you == " s " :             return 1     elif comp == " g " :         if you == " w " :             return 0         elif you == " s " :             return 1 print ( " Computer turn : Snake(s),Water(w) or Gun(g) " ) randno = random . randint ( 1 , 3 ) if randno == 1 :  ...