Posts

Showing posts from April, 2022

Raise keyword in python

#raise is a built-in keyword used to raise exception # visit all built-in Exceptions and understand name= input ( "enter u r name:" ) if name.isnumeric(): raise Exception ( "numbers r not allowed" ) #here we used raise keyword

Typedef keyword in c

// typedef is a keyword which is used to give name to the existing data type // syntax- typedef <previous_name> <alias_name>; #include <stdio.h> int main () {     typedef int nt ; // here i given a new name to the data type int to 'nt'     nt a ;           // now i can use 'nt' in place of int     // it is not neccesary to use alias name or new name i can use previous name also like u can see below     int b ;     //--------------------     // using typedef with structure     typedef struct library     {         char name [ 20 ];         int pages ;         char author [ 20 ];     } lib ;             // here i given a new name to the data type library(structure) to 'lib'     lib book1 , book2 ; // here now i can use 'lib' instead of 'struct libra...

structure in c

//structures are user defined data types in c //in structures we can store any type of data types like int floate char etc //declaring a structure #include <stdio.h> #include <string.h> struct library //here strut is a keyword for creating a structure, here library also called structure tag {     char name [ 20 ]; //members or elements of library tag or structure name     int pages ;     char author [ 20 ]; //character array or string of size 20, we have to use string for a char value //there are two methods to initialize a variable from structure }; //book1; //method 1 int main () {     struct library book1 , book2 ; //method 2     //there are two ways to assign values to the variables     //struct library book1={'h',2,'s'}; //way 1,but this is an error, like this we can only assign int values not char     strcpy ( book1 . name , "softwareharish" ); //way 2     book1 . pages = 100 ; ...

python speak

#from pywin32 module we can make read the sentences by the computer from win32com.client import Dispatch speak=Dispatch( "sapi.spvoice" ) speak.speak( "harish is a champion in coding " ) #in function def speak (str): from win32com.client import Dispatch speak = Dispatch( "sapi.spvoice" ) speak.speak(str) if __name__== '__main__' : speak( "jai ntr" )

string functions

#include <stdio.h> #include <string.h> //string functions library int main () {     char s1 [] = "harish" ; //string1     char s2 [] = "shiva" ; //string2     char s3 [ 10 ];     //puts(strcat(s1,s2)); //concatenation     printf ( "length of s1: %d \n " , strlen ( s2 )); //give length of string     printf ( "the reversed string of s1: " );     puts ( strrev ( s1 )); //reverse the string     //s3=strcat(s1,s2); //you canot do like this     strcpy ( s3 , strcat ( s1 , s2 )); //copy value in another variable     printf ( "s3 copied from s1 and s2:" );     puts ( s3 );     return 0 ; }

triangular star

#include <stdio.h> char printstar ( int rows ); int main () {     int n , row , j ;     char star = '*' ;     printf ( "enter 1 for triangle star \n 0 for reverse triangle star \n " );     printf ( "enter:" );     scanf ( " %d " ,& n );     if ( n == 0 )     {         printf ( "enter no of rows u want:" );         scanf ( " %d " ,& row );         for ( j = row ; j >= 1 ; j --)         {             printstar ( j );         }     }     else if ( n == 1 )     {         printf ( "enter no of rows u want:" );         scanf ( " %d " ,& row );         for ( j = 1 ; j <= row ; j ++)         {             printstar ( j ); ...

Fibbonachi series

#include <stdio.h> int recursive ( int n ); int iterative ( int n ); int main () {     int n , fib1 , fib2 ;     printf ( "enter no of which u want fibbonachi:" );     scanf ( " %d " ,& n );     fib1 = recursive ( n );     fib2 = iterative ( n );     printf ( "recursive fibonachi is %d \n " , fib1 );     printf ( "iterative fibonachi is %d " , fib2 );     return 0 ; } int recursive ( int n ) {     if ( n == 1 || n == 2 )     {         return n - 1 ;     }     else     {         return recursive ( n - 1 )+ recursive ( n - 2 );     } } int iterative ( int n ) {     int a = 0 , b = 1 ;     for ( int i = 0 ; i < n - 1 ; i ++)     {         b = a + b ;         a = b - a ;     }     return a ; }

some conversions

// 1kg = 2.205 pounds // 1km = o.621 mile // 1 foot = 12 inch // 1 meter = 3.280 foot // 1 inch = 2.54 cm #include <stdio.h> int main () {     char input ;     float quantity , result ;     float kgtopound = 2.205 ;     float kmtomile = 0.621 ;     float foottoinch = 12 ;     float mtofoot = 3.280 ;     float inchtocm = 2.54 ;     while ( 1 )         {             printf ( "enter q to quiet \n    1.kg to pound \n    2.km to mile \n    3.foot to inch \n    4.m to foot \n    5.inch to cm \n " );             scanf ( " %c " ,& input );             switch ( input )             {                 case 'q' :                 p...

array reversing

#include <stdio.h> void arr_rev ( int arr [] ) //reversing array user built function {     for ( int i = 0 ; i < 5 / 2 ; i ++)     {         //swaping method         int temp ;         temp = arr [ i ];         arr [ i ]= arr [ 4 - i ];         arr [ 4 - i ]= temp ;     } } int main () {     int arr [] ={ 1 , 2 , 3 , 4 , 5 };     for ( int j = 0 ; j < 5 ; j ++)     {         printf ( "element of %d is %d \n " , j , arr [ j ]);     }     printf ( "reversed array \n " );     arr_rev ( arr );     for ( int j = 0 ; j < 5 ; j ++)     {         printf ( "element of %d is %d \n " , j , arr [ j ]);     }     return 0 ; }

Dictionary

d1={ } #dictionary print ( type (d1)) d2={ "name" : "n harish" , "aim" : "softwareharish" , "gf" : "single king" , "salary" : 10000 } print (d2) print (d2[ "name" ]) d2[ "nick name" ]= "shiva" #adding another key value pair print (d2) del d2[ "gf" ] #delete key value pair print (d2) #some functions of dictionary d3=d2.copy() #copy the dictionary print (d3) print (d2.get( "aim" )) # access key value pair d2.update({ "propery" : "laptop" }) #update dictionary print (d2) print (d2.keys()) #give all keys of dictionary print (d2.items()) #give all items of dictionary

RE (regular expression) module

Image
  Above everything will be used in re module that is  1. metacharacters 2. Special sequences 3. Sets