Codelybrary
My collection of useful facts and experiences.
I am also active at:
Sunday, May 19, 2024
Friday, May 17, 2024
Wednesday, May 15, 2024
Syllabus of core Python
Python installation
The Command Line
Jupyter Notebook
Python Comments
The print statement
Variables
Constants
Keywords
Numbers
Strings
Lists
Dictionaries
Tuples
Sets
Control Flow
IF, ELIF and ELSE statements
Comparison operators
For loops
While Loops
Nest Loops
Break, Continue and Pass keywords
enumerate
List Comprehensions
Dictionary Comprehensions
How to use Functions
How to create your own Functions
Parameters and arguments
*args and **kwargs
lambda expressions
Map and Filter functions
Python Scope
Accepting and validating user input
Object Oriented Programming (OOP)
Inheritance
Polymorphism
Special Methods
Modules & Packages
How to create your own packages
Errors and Exceptions handling
Decorators
Generators
Web Scraping using the requests and BeautifulSoup libraries
GUI's using Tkinter
Dashboards using plotly and dash
Work with CSV files, PDF files and Databases
The Collections module
Regular Expressions (regex)
Timing your Python Code
Friday, April 26, 2024
Sacred Thought
5 May 2024
Hari Om
Verse 50-51, chapter two:
In this chapter two Shree krishna explains a simple way of living.
Free from desires and void of possessions, go on efficiently doing your duties with evenness of mind
in their success or failure. Strive for the practice of this yoga of equanimity, possessing equipoised
mind you will attain the blissful supreme state.
Hari Om Tat Sat!
----------------------------------------------------------------------------------------------------------------------
30 April 2024
Verse 38-53 chapter two simplified:
Practice yoga of mind as you perform your daily duties.
Yoga of mind is being even-minded in both success (completion) and failure in what ever task you do.
Try your best to do it in the best possible way, but if you don't succeed in it then don't get upset or unhappy.
Don't get too much happy by success nor get too sad by failures. Soon you will reach a state of mind
where success and failure won't affect you much.
Thus by being steady and undistracted by worldly affairs, you will attain Yoga - Everlasting Union with God!
----------------------------------------------------------------------------------------------------------------
28 April 2024
Today I am going to explain verse 31 - 38 chapter two for you all.
There is no opportunity better than a righteous war (सत्य और न्याय की लड़ाई ). So, always fight for the truth in your life.
There are only two possible out comes of this war. Either you win or you lose. If you win, then what to say,
you will rule the world but in case even if you lose(die), you will attain heaven after death.
So its a win-win situation. Never miss such opportunity to fight for what is right in your day to day life. Come
forward and fight. As there are only two possible out comes, and you win in either case.
चुप ना रहो, हमेशा सत्य और न्याय के लिए लड़ो , फिर वो किसी के लिए भी क्यों ना हो। अन्याय और जुर्म का साथ मत दो ना ही उसे सहो |
------------------------------------------------------------------------------------------------------------------------
26 April 2024
Dear friends, I write the explanation of two verses of Geets for all of you, I hope you all will like it and benefit from it.
In Shreemad Bhagwat Geeta , the song celestial, one full chapter (chapter 16) has been devoted towards explaining the differences between the two tendencies within an individual, the good and evil, the divine and demoniac.
Verse 3 indicates divine virtues: Splendor, forgiveness, fortitude, purity, absence of malice, absence of pride, these all are the qualities of those endowed with divine virtues.
Verse 4 indicates demoniac virtues: Hypocracy, arrogance, pride, anger, harshness, and ignorance are the marks of the one who is born of demonical properties.
Even one of these divine virtues, say for example 'purity', attained by an individual will impart in him the remaining virtues rather automatically and make him a blissful person.
On the other hand any of the demonical properties like 'anger' will bring him miseries in plenty and will lead to his utter downfall.
Needless to say you should adopt to more and more of divine virtues in your day to day life to attain bliss.
Sunday, March 10, 2024
Basic Trubo C++ programs
/*
A C++ program to accept ten numbers in ascending order using array.
and search for a number given by user using binary search method.
*/
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
//Declare all variables.
int arr[10], i, initial, final, mid, data;
cout<<"Enter 10 numbers in ascending order ";
for( i = 0; i<10; i++)
{
cin >> arr[i];
}
cout<<"\nEnter the data to be searched : ";
cin >> data;
initial = 0;
final = 9;
mid = (initial + final)/2;
while( initial <= final) && (arr[mid] != data))
{
if( arr[mid] > data)
final = mid - 1;
else
initial = mid + 1;
}
if( arr[mid] == data)
cout<<"Data is present";
if(initial > final)
cout<<"Data is not present in the list";
getch();
}
---------------------------------------------------------------------------------------------------------------
/*
A C++ program to accept 10 numbers in an array and sort the numbers
in ascending order using Bubble sort method. Practical 15.
*/
#include<iostream.h>
#include<conio.h>
void main()
{ clrsrc();
//Declare all variables.
int arr[10], i, j , temp;
cout<<"Enter 10 numbers ";
for( i = 0; i<10; i++)
cin>> arr[i];
//Bubble sort.
for( i = 0; i <10; i++)
{
for(j = 0; j<10; j++)
{
if( arr[j] > arr[j +1])
{
//swap the two.
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
cout<<"The sorted array is \n";
for( i =0; i < 10; i++)
cout<< arr[i]<<" ";
getch();
}
-------------------------------------------------------------------------------------------------------------
/*
A C++ program to accept 10 numbers in an array and sort the numbers
in ascending order using Selection sort method.
*/
#include<iostream.h>
#include<conio.h>
void main()
{ clrsrc();
//Declare all variables.
int arr[10], i, j, temp;
//prompt user to enter 10 numbers.
cout<<"Enter any 10 numbers ";
//Store the numbers in an array.
for( i =0; i<10; i++)
cin >> arr[i];
//Selection sort.
for( i = 0; i <10; i++)
{
for(j = 0; j<10; j++)
{
if( arr[i] > arr[j])
{
//swap the two.
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
cout<<"The sorted array is \n";
for( i =0; i < 10; i++)
cout<< arr[i]<<" ";
getch();
}
----------------------------------------------------------------------------------------------------
/*
A C++ program to insert a data in an array, at a given location or at its end.
*/
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
//Declare all the variables.
int arr[20], i, loc, n, data;
//prompt user to enter the number of elements ";
cout<<"Enter the size of the array ";
//store size in 'n'.
cin >> n;
cout<<"Enter the array elements\n";
for( i =0; i<n; i++)
cin >> arr[i];
cout<<"enter the location after which the data is to be inserted \n";
cin >> loc;
//Shift all the elements after loc to the right of the array by one.
for( i = loc + 1; i < n - loc; i++)
{
arr[i+1] = arr[i];
}
cout<<"Enter data to be inserted at "<<loc;
cin >> arr[loc];
//Increment size by 1
n++;
cout<<"Array after insertion \n";
for( i =0; i<n ; i++)
cout<<arr[i]<<" ";
getch();
}
-------------------------------------------------------------------------------------------------------------
/*
A C++ program to delete a data in an array, at a given location or at its end.
*/
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
//Declare all the variables.
int arr[20], i, loc, n, data;
//prompt user to enter the number of elements ";
cout<<"Enter the size of the array ";
//store size in 'n'.
cin >> n;
cout<<"Enter the array elements\n";
for( i =0; i<n; i++)
cin >> arr[i];
cout<<"enter the location after which the data is to be inserted \n";
cin >> loc;
//Shift all the elements after loc to the right of the array by one.
for( i = loc + 1; i < n - loc; i++)
{
arr[i+1] = arr[i];
}
cout<<"Enter data to be inserted at "<<loc;
cin >> arr[loc];
if( loc != 0)
{
//Shift all the elements after the location to the left by 1.
for (i = loc+1; i < n; i--)
{
arr[i] = arr[i + 1];
}
}
//Decrement size by 1
n--;
cout<<"Array after insertion \n";
for( i =0; i<n ; i++)
cout<<arr[i]<<" ";
getch();
}
----------------------------------------------------------------------------------------------------------------
/*
A C++ program to swap two numbers using call by value
and call by reference. Practical 11.
*/
#include<iostream.h>
#include<conio.h>
//Function prototype declaration for call by reference.
void swapReference(int *, int *);
void main()
{
clrscr();
//Declare all variables.
int a, b, temp, choice;
//Menu.
cout<<"Enter '1' for swapping using call by value \n";
cout<<"Enter '2' for swapping using call by reference \n";
cout<<"Enter '0' to exit \n";
//Menu options using switch statement.
switch(choice):
{
case 1:
cout<<"Enter any two numbers : \n";
cin >> a >> b;
cout<<"Before swap a = "<<a<<" b = "<<b;
temp = a;
a = b;
b = temp;
cout<<"\nAfter swap a = "<<a<<" b = "<<b;
break;
case 2:
cout<<"Enter any two numbers : \n";
cin >> a >> b;
cout<<"Before swap a = "<<a<<" b = "<<b;
swapReference(&a, &b);
cout<<"\nAfter swap a = "<<a<<" b = "<<b;
break;
case 0:
cout<<"Thank you\n";
break;
default:
cout<<"Invalid input! try again. \n";
}
getch();
}
//Function definition.
void swapReference(int * a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
--------------------------------------------------------------------------------------------------------
/*
A C++ program to print all the Pythagorean triplets between 1 and user given limit using
Turbo C++ compiler.
*/
#include<iostream.h>
#include<conio.h>
void main()
{
//Declare int variables.
int a, b, c, sum = 0, limit;
//Prompt user to input upper limit.
cin>>limit;
for(a = 1; a<limit; a++)
{
for(b = 1; b<limit; b++)
{
for(c = 1; c<limit; c++)
{
if( a*a == (b*b + c*c) && (a+b+c) != sum)
{
//To filter duplicate triplets.
sum = a+b+c;
//Print the triplets.
cout<<a<<" "<<b<<" "<<c<<endl;
}
}
}
}
getch();
}
--------------------------------------------------------------------------------------------------
/*
A C++ program to count the number of characters and words in a sentence entered by user.
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int chars=0, words = 1;
char c;
while((c=getche()) != '\r')
{
if(c == ' ')
words++;
else
chars++;
}
cout<<"Number of characters "<<chars;
cout<<"\nNumber of words "<<words;
getch();
}
----------------------------------------------------------------------------------------------------------------------
/*
A C++ program to return cube of a number using inline function.
*/
#include<iostream.h>
#include<conio.h>
//Declare the inline function.
inline int cube(int a)
{
return a*a*a;
}
void main()
{
clrscr();
//Declare all variables.
int number, cube;
//Prompt user to enter a number.
cout<<"Enter a number ";
//Store user input in the integer variable 'number'.
cin>>number;
//Pass number as argument to the inline function 'cube()'.
cube = cube(number);
cout<<"The cube of the number is :"<<cube;
getch();
}
-------------------------------------------------------------------------------------------------------------------
/*
A C++ program to convert all upper case letters of a word to
lower case and vice-versa.
*/
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
clrscr();
//Declare all variables.
int i=0, j=0;
char word[50];
//prompt user to enter a word.
cout<<"Enter a word ";
cin>>word;
//Replace lower case with upper and vice-versa.
while(word[i] != '\0')
{
if( isupper(word[i]))
{
word[i] = tolower(word[i]);
i++;
}
else
{
word[i] = toupper(word[i]);
i++;
}
}
//Print the new word with case reversed.
while( word[j] != '\0')
{
cout<<word[j];
j++;
}
getch();
}
--------------------------------------------------------------------------------------------------------------------
/*
A C++ program to get maximum of given numbers.
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int max, i;
A[5] = {12,54,6,99,2};
max = A[0];
for(i=1; i<5; i++)
{
if max < A[i];
{
max = A[i];
}
}
cout<<"The maximum value is "<<max;
getch();
}
Wednesday, January 17, 2024
Pandas, Numpy and Matplotlib: Basic Python libraries for Loading data from data files into our Python program.
Install all these three libaraies using the following commands:
pip install pandas
pip install numpy
pip install matplotlib --user
Now, open the Python interpreter and import each in your Python program as follows:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
Now start using each of them in your program as follows:
df = pd.read_csv('location path of the .csv file from which data has to be loaded')
How can I run a C++ program directly from Windows?
How-can-I-run-a-C-program-directly-from-Windows
-
Acronym Full Form AJAX Asynchronous JavaScript and XML API Application Programming Interface APK Android Application Package ASP Activ...
-
#include<stdio.h> int main() { int M,N,q; scanf("%i %i",&M, &N); if((M%N)!=0) {printf("0&quo...
-
"A good company understands that problem solving ability and the ability to learn new things are far more important than knowledge o...