Wednesday, April 4, 2018

Tuesday, April 3, 2018

Python Decision Making

Python - Decision Making

Decision Making in Python Decision making involves the anticipation of the conditions that occur during the execution of a given program and specifying the actions based on the conditions. Multiple expressions will be evaluated by the decision structures and they produce a Boolean value that is either TRUE or a FALSE. And the user will need to determine the action to be taken and the statements to be executed basing on the outcome.

The decision-making structure that is found in all major programming languages is given below.

decision making statement

In Python, any non-null and non-zero values will be assumed as TRUE. If the value obtained is either null or zero, the Python assumes it as a FALSE.

The decision making statements that are provided by the Python programming language are stated below.

These are used in order to check if the given condition is satisfied or not.


 a = 1   

if a > 5: 

print "This shouldn't happen." else:

 print "This should happen." O/p: This should happen 


 z = 4 

if z > 70: 

print "Very Wrong" elif z < 7: 

print "This is normal" O/p: This is normal 

             It is to be noted that the else if is shortened to elif in python. We can use multiple elif’s but only one else statement. End of every sentence should have a colon. Even indentation sometimes helps to differentiate the statements that are in the conditional statements or not.

          Single Statement Suites The suit of given if the statement can go on the same line of the header statement in cases where the if clause has a single line. For you to get a better understanding of single line suites, go through the following example.


one-line if clause− 


var = 100

if ( var == 100 ) : print "The value of the given expression is 50" print "Good bye!"

The above code gives the following result− The value of the given expression is 50 Good bye!

Thursday, February 15, 2018

What is python Programming Languages

What is  python Programming Languages

Read more Languages:-

As you might have already known, Python is basically a high level programming language. A programming language is considered high level if it is machine independent and uses human languages like English to specify its syntax, so that it can be easily understood by a human. The programmers just need to deal with the English-like syntax and does not have to worry about the underlying machine code. Although there are many high level languages available in the market, Python has become widely popular among software developers for its clear-cut syntax and easy readability. The lines of actual code in Python have the look of a pseudo-code and hence are easily understandable.

Why is the readability of a programming language so important in software development? It is because; more time is spent by the programmers in reading the lines of code than writing it. Python makes this task easier by laying huge emphasis on code readability. Also, Python can perform a given task using lesser number of lines of code when compared to other high level languages like Java or C++.

 Python can be described as follows:-

 Python is a free, open source, general purpose and object oriented programming language.

Since Python is a free and open source software, its source code can be freely accessed, modified and reused. It is object oriented, which means it involves the usage of classes and objects in programming. It is used for developing applications in a wide variety of domains, making it a ‘general-purpose’ programming language. It has a potential number of users in the software community.

Python was initially developed by Guido Van Rossum, from 1985-1995. Python reduced many complexities of application development because it used English key words, which are easily understood unlike other languages, which require a lot of punctuations. Adding to it is the minimum requirement of syntaxes to be developed.

The following can be said about Python:-

◆  Python is interpreted:-

This indicates that the processing is done by an interpreter at run time and one need not compile one’s program before it being executed. This is closely related to the various languages like PHP Languages and PERL Languages.

◆  Python is Interactive:-

This means, you can directly interact with the Python prompt and execute the programs.

◆  Python is Object-Oriented:-

This indicates that Python deals with the object oriented programming i.e. we can encapsulate the code within the created objects.

◆   Language for beginners:-

Python is a good language to start off with for beginners and programmers who have just started with coding. It also extends its support to developing variety of games related to both text and web.

Python Features:-

◆  Easy-to-learn:-

Python has simple structure, lesser keywords and a well-defined syntax, which allows the learner to understand it in a lesser period of time. Easy-to-read: The code is well defined, as it requires minimum syntax build.

◆  Easy-to-read :-
Its source code is easy-to-maintain when compared to other languages.

◆   Standard library:-

One of its biggest strengths is that it has got a bulk library that is portable and is compatible on various Operating Systems like UNIX, Macintosh and Windows.

◆  Interactive Mode:-

Python supports an interactive mode where results can be entered from a terminal system and can debug the code using this mode.

◆  Portable:-

Python gives the same User Interface when it is run on various hardware platforms.

◆  Extendable:-

Adding up of lower level sections to the Python interpreter is possible. These low-level modules help programmers to use customized tools to increase their efficiency.

◆    Databases:-

It provides connection with major databases available in market.

◆   GUI Programming:-

Python supports graphical user interface that can be developed and for different libraries, system calls, and Operating Systems, like Macintosh, Windows MFC, and X Window system of Unix.

◆   Scalable:-

Python provides a simple and a better structure and supports larger programs than other scripting languages like Shell.

Python as a Scripting Language:-

Python’s robust features as a programming language helped it to prove its versatility by standing out as a scripting language too.

Scripting Languages are nothing but programming languages, which are mostly used for controlling software applications. They support scripts or programs that are only written for runtime operations. ‘Scripts’ do not get compiled but get interpreted; whereas the applications controlled by them are usually compiled. Thus, scripts are different from the core application programs. Scripts and application programs are usually written using different languages. Usually, controlling of the application program by the script occurs by embedding the script into the application program.

Benefits of using Python:-

●. Being a dynamic programming language, Python can exhibit certain behaviors during runtime, which the static programming languages can exhibit only during the compile time.

●.  The variable type in Python can be quickly changed without any fuss or errors. It is not possible to do the same in case of static programming languages as the variable type cannot be changed during the progression of the program. It can be easily integrated with other technologies.

●.  Python has been designed such that it can be easily embedded into other technologies. The productivity of the programmers greatly increases while working with Python, because of its simplicity, readability and support libraries that are easy to use.

●.   Web services can be easily developed using Python. Python is an ideal programming language to work with, if the projects undertaken are big or complex, whose requirements change often. Scientific applications make use of tools like numeric Python and Scientific Python.

●.   In general, an ideal programming language for scientific research is the one that allows notepad or paper scribbling to be directly translated into a piece of code. Python does the job with much √©lan as it looks more like an easy to read pseudo code.

●.    Python is free software and can be freely used for commercial purposes too. Read More

Friday, February 9, 2018

Introducing to Python Programming Languages

Introducing to  Python Programming Languages

Introducing to  Python Programming Languages

Learn More Languages

Even though the foundation for computer programming has been laid by mathematicians in as early as the 1800’s, it has taken nearly hundred years thereafter, for a proper programming language to emerge. Since then, programming languages have evolved from complicated low level instructions to sophisticated, easy to read high level languages. Programming resulted in the development of software systems, which revolutionized the field of computer science. 

Software can be thought of as a technical literature, which can be read by both computers and humans, but not in the same form. Humans can easily understand software only if it is written in a human readable language like English. On the other hand, computers can only understand instructions, which are in the form of machine code (0’s and 1’s). So, certain programs (compilers and interpreters) that can translate high level code to machine code have been developed. 

Even though high-level languages are easy to understand, most of them have complicated syntaxes, which make writing and modifying large programs cumbersome. Hence, high-level languages with simple, clear-cut syntaxes have been released and Python is one such language. Because of its simple syntax, high readability and various other innovative features, programmers all over the world are growing fond of Python. In the recent times, because of its simplicity, several universities have adopted Python to teach introductory computer programming to students. 

Thus, Python is not only getting popular among software developers, but is also gaining popularity as an ideal language to start learning computer programming. If you are new to programming, this book is an ideal place to start learning how to write code. If you are well acquainted with programming, this blog will be an easy read to you and will make you understand what sets Python apart from other programming languages. Read More

Wednesday, February 7, 2018

Conversion specifiers in C Languages

Conversion specifiers in C Languages
Conversion specifiers in C Languages 

There is a specific set of conversion specifiers for printf and another specific set of conversion specifiers for scanf. You have to keep in mind that the conversion characters used for scanf are not the same as those used for printf. Hence, you have to be careful when using them in your program. See to it that you become familiar with the long types.

The following are the conversion specifiers for printf:-

You have to take note that the lowercase letter l may be used as a prefix for long types.

u – it means unsigned denary integer

d – it means signed denary integer

o – it means octal integer

x – it means hexadecimal integer

s – it means string

g – it means use e or f, whichever one is shorter

f – it means a fixed decimal floating point

c – it means a single character

e – it means scientific notation floating point

The following are the conversion specifiers for scanf: -

ld – it means long int

d – it means denary integer

o – it means octal integer

x – it means hexadecimal integer

f – it means float type

h – it means short integer

lf – it means double or long float

e – it means float type

c – it means single character

le – it means double

s – it means character string   READ MORE

Saturday, February 3, 2018

PHP Get & Post Method Tutorial Learne

PHP Get & Post Method Tutorial Learne
Get & post method

The client browser uses two methods to send information from the client to the web server. These methods are GET and POST. However, before sending the information, the browser first encodes the information using the coding scheme called URL encoding. In this coding scheme, key-value pairs, which are here name-value pairs, are combined together in such a way that different name-value pairs are separated by & (ampersand). Any whitespaces are replaced by the plus sign (+) and non-alphanumeric characters are replaced with their hexadecimal values. Once the encoding process is over, the data is sent to the web server.

The GET Method 

When the GET method is used for sending information to the web server, it send the same along with the page URL. The URL is appended by the encoded information and the question mark sign (?) separates the former from the latter. Some of the key things to note about the use of this method include –

●    Since this method appends the page URL, the sent information will also appear in logs of the server.

●       The maximum number of characters that can be sent using the GET method is 1024 characters.

●           There is an inherent issue of compromised confidentiality with this method. Therefore, its use must be avoided when you are sending passwords or critical information to the web server.

●             Another inherent limitation of the GET method is that documents and images cannot be sent to the server using this method.

●             Besides the above-mentioned, it is also possible to access the data sent using this method by retrieving the QUERY_STRING environment variable. Therefore, data is not safe.

●             It is possible to access all the sent information using this method by accessing $_GET, which an associative array provided by PHP for this purpose.

You can try the sample code given below to understand how this method is used.


if( $_GET["name"] || 

$_GET["age"] ) 

echo "Welcome ". $_GET['name']. "<br />"; 

echo "You are ". $_GET['age']. " years old."; 





<form action = "<?php $_PHP_SELF ?>" method = "GET"> 

Name: <input type = "text" name = "name" /> 

Age: <input type = "text" name = "age" /> 

<input type = "submit" /> 




The POST Method 

An alternative to the GET method is POST method. This method makes use of HTTP headers to transfer information from the client to the server. The encoded information is put into the header. Some of the things that you must know about the use of this method for information transfer has been listed below –

●   Unlike GET method, there is no limitation on the number of characters that can be sent using this method.

●    It is possible to send binary as well as ASCII data using this method.

●     As far as the security of data is concerned, data security totally lies in the hands of the HTTP protocol. You can ensure higher security of data by using HTTP Secure.

●     All the data using the POST method can be accessed using the $_POST associative array.

You can try the sample code given below to understand how this method is used.


if( $_POST["name"] || 

$_POST["age"] ) { if (preg_match("/[^A-Za-z'-]/",$_POST['name'] )) 

die ("Name is invalid!"); 

echo "Welcome ". $_POST['name']. "<br />"; 

echo "You are ". $_POST['age']. " years old."; 





<form action = "<?php $_PHP_SELF ?>" method = "POST"> 

Name: <input type = "text" name = "name" /> 

Age: <input type = "text" name = "age" /> 

<input type = "submit" /> 




The $_REQUEST Variable 

The contents of $_GET and $_POST are available in $_REQUEST. Besides this, $_REQUEST also contains data associated with $_COOKIE. The form data sent to the web server using both the methods namely GET and POST can be accessed by accessing this variable. Here $_PHP_SELF variable contains the name of self script in which it is being called.

Thursday, February 1, 2018

Access Control Modifiers in PHP

Access Modifiers 

Access Modifiers are keywords that control visibility of class properties and methods. In PHP there are three of them:

1. Private 

2. Protected 

3. Public 

Let’s describe Mindi in terms of her own class and let’s say that Mindi has a tattoo on her wrist. We could put it in PHP terms like this:

When we do it this way, the tattoo is public by default. That means it can be seen anywhere in the program. It's the same as writing it as:

Class mindi {

Public $ tattoo_location

This means class Billy or class Alex or class Dad can all see Mindi's tattoo because it has public visibility which is set by a public access modifier.

Now let's say Mindi instead has a tattoo that she doesn't want class mom or class dad to know about but wants to show off to her friends. She has this tattoo on her back so she can display it wearing a bikini top.

Class mindi {

Protected $tattoo_location;

Protected function setlocation () {}


Now Mindi can wear her bikini top around her friends and not her mom or dad. We can describe this in PHP by extending an invitation to the people she wants to show it to by using the extends key word:

Since all of these classes extend class Mindi, they can see her tattoo. This is inheritance and all of these classes that extend Mindi are part of her inheritance hierarchy. Now let's say she has her tattoo in a more intimate place (use your imagination) and she only wants her boyfriend Billy to see it and no one else. In PHP terms:

Class mindi {

Private tattoo_location;

Private setlocation ( ) { }

Private letbillysee ( ) { }


So to summarize the three PHP access Modifiers in a more formal way:


restricts the access to the class itself. Only methods that are part of the same class can access private members. Let’s look at an example below:

The reason why data members are declared private is to avoid the outside programs to unintentionally modify the values without necessary validation. If you make a data member private you should provide public getter/setter methods to access the value of this data member. The access modifier


Allows the class itself and all of it’s subclasses to access the data members and member functions. Global access is denied.


means that any code can access the member by its name.

Now back to my previous point about object-oriented principles being “global” in the way a developer should think of them. I used Mindi's tattoo to explain access modifiers but I also had to demonstrate encapsulation and inheritance in order to do so. Inheritance and Encapsulation are really just ways of regulating the ability of an object defined that is defined by a class.

Wednesday, January 31, 2018

PHP Array tutorials with example


One of the most useful data structures supported by PHP is arrays. An array is a collection of data elements that are of the same type. For instance, if you wish to store 20 integers, then it can be stored in an array of 20 elements. You can also look at arrays as a collection of variables of the same type; each of which is capable of storing data.

PHP supports three types of arrays, which include  :- 

•   numeric arrays, 
•   multi-dimensional arrays  
•   associative arrays. 

The individual elements of the array can be accessed using the index or position of the element in the array. The three types of arrays differ in the manner their elements are accessed. Numeric arrays have numeric index that are incremented in a linear fashion. For instance, the first element of the array has the default index of 0. For all elements succeeding this data value, the index is incremented by 1.

            On the other hand, associative arrays have strings as index. The array is composed in a key-value fashion and the keys are stored as index while the values are accessed using the keys. Therefore, the storage of elements and their accessibility is dependent upon the association between the key and value.

Lastly, an array can be composed of elements each of which is an array in itself. Such an array is 2-dimensional. Correspondingly, the dimensionality of an array can be increased depending on the programming requirement. Arrays that have multiple dimensions are called multi-dimensional arrays. Moreover, the elements of such arrays are accessed using multiple indices.

◆   Numeric Array 

Numeric arrays can store any type of data like strings, numbers and objects. However, the only thing worth remembering is that the array’s indices are numeric. Moreover, the default index of the first element of the array is zero. The function used to create arrays is array(). Sample code to demonstrate the functionality of numeric arrays is given below for your reference.

◆   Associative Arrays 

Associative arrays are similar to numeric arrays in the way they function. However, their indexing mechanism is different. They work on the key-value format. Values have keys, which are The associative arrays are very similar to numeric arrays in term of functionality but they are different in terms of their index. Associative array will have their index as string so that you can establish a strong association between key and values.

For instance, if you need a data structure to store the salaries of employees, then the same can best be done using an associative array. In this case, employee names can be used as keys and salaries as values. Please note that you must never put associative arrays inside double quotes as they don’t return any value in that case. Sample code to demonstrate the functioning of associative arrays is given below –




/*Creating associative array using method 1*/ 

$salary = array('james' => 20000, 'jacob' => 15000, 'maria' => 7500); echo "Salary of first employee is ". 

$salary['james'] . "<br />"; echo "Salary of second employee is ". 

$salary['jacob']. "<br />"; echo "Salary of third employee is ".  

$salary['maria']. "<br />"; 

/*Creating associative array using method 2*/ 

$salary['james'] = "high"; 

$salary['jacob'] = "medium"; $salary['maria'] = "low"; 

echo "Salary of first employee is ". $salary['james'] . "<br />"; 

echo "Salary of second employee is ". $salary['jacob']. "<br />"; 

echo "Salary of third employee is ". $salary['maria']. "<br />"; 




◆   Multi-dimensional

Arrays In a multi-dimensional array, every element of the array is also an array. Therefore, a multi-dimensional array is composed arrays, which in turn can also be made up of arrays. In order to access elements of a multi-dimensional array, multiple indices must be used. Sample code to demonstrate the functioning of multi-dimensional arrays is given below –

Monday, January 29, 2018

Decision Making in PHP

Making Decisions

Like most programming languages, PHP lets you write code that can make decisions based on the result of an expression. This allows you to do things like test if a variable matches a particular value, or if a string of text is of a certain length. In essence, if you can create a test in the form of an expression that evaluates to either true or false, you can use that test to make decisions in your code.

You studied expressions, but you might like to quickly review the “Operators and Expressions”section in that chapter to give yourself an idea of the kinds of expressions you can create. You can see that, thanks to the wide range of operators available in PHP, you can construct some pretty complex expressions. This means that you can use almost any test as the basis for decision-making in your code.

PHP gives you a number of statements that you can use to make decisions:

•  The if statement
•  The else and elseif statements
•  The switch statement

You explore each of these statements in the coming sections.

◆  Simple Decisions with the if Statement

The easiest decision-making statement to understand is the if statement. The basic form of an if construct is as follows:

if ( expression )

// Run this code

// More code here

If the expression inside the parentheses evaluates to true, the code between the braces is run. If the expression evaluates to false, the code between the braces is skipped. That’s really all there is to it.

        It’s worth pointing out that any code following the closing brace is always run, regardless of the result of the test. So in the preceding example, if expression evaluates to true, both the Run this code and More code here lines are executed; if expression evaluates to false, Run this code is skipped but More code here is still run.

Here’s a simple real-world example:

$widgets = 23; 

if ( $widgets == 23 )

echo "We have exactly 23 widgets in stock!";


The first line of the script creates a variable, $widgets, and sets its value to 23. Then an if statement uses the == operator to check if the value stored in $widgets does indeed equal 23. If it does —and it should! —the expression evaluates to true and the script displays the message: “We have exactly 23 widgets in stock!”If $widgets doesn’t hold the value 23, the code between the parentheses —that is, the echo() statement —is skipped. (You can test this for yourself by changing the value in the first line of code and re-running the example.)

 Here’s another example that uses the >= (greater than or equal) and <= (less than or equal) comparison operators, as well as the && (and) logical operator:

$widgets = 23; 

if ( $widgets >= 10 && $widgets <= 20 )

echo "We have between 10 and 20 widgets in stock.";


This example is similar to the previous one, but the test expression inside the parentheses is slightly more complex. If the value stored in $widgets is greater than or equal to 10, and it’s also less than or equal to 20, the expression evaluates to true and the message “We have between 10 and 20 widgets in stock.”is displayed. If either of the comparison operations evaluates to false, the overall expression also evaluates to false, the echo() statement is skipped, and nothing is displayed.

The key point to remember is that, no matter how complex your test expression is, if the whole expression evaluates to true the code inside the braces is run; otherwise the code inside the braces is skipped and execution continues with the first line of code after the closing brace. You can have as many lines of code between the braces as you like, and the code can do anything, such as display something in the browser, call a function, or even exit the script. In fact, here’s the previous example rewritten to use an if statement inside another if statement:

The code block between the braces of the first if statement is itself another if statement. The first if statement runs its code block if $widgets >= 10, whereas the inner if statement runs its code block —the echo() statement —if $widgets <= 20. Because both if expressions need to evaluate to true for the echo() statement to run, the end result is the same as the previous example.

If you only have one line of code between the braces you can, in fact, omit the braces altogether:

$widgets = 23;

if ( $widgets == 23 ) 

echo "We have exactly 23 widgets in stock!";

However, if you do this, take care to add braces if you later add additional lines of code to the code block. Otherwise, your code will not run as expected!

◆   Providing an Alternative Choice with the else Statement :- 

As you’ve seen, the if statement allows you to run a block of code if an expression evaluates to true. If the expression evaluates to false, the code is skipped.

You can enhance this decision-making process by adding an else statement to an if construction. This lets you run one block of code if an expression is true, and a different block of code if the expression is false.


if ( $widgets >= 10 )


echo "We have plenty of widgets in stock."; } else


 echo "Less than 10 widgets left. Time to order some more!";


If $widgets is greater than or equal to 10, the first code block is run, and the message “We have plenty of widgets in stock.”is displayed. However, if $widgets is less than 10, the second code block is run, and the visitor sees the message: “Less than 10 widgets left. Time to order some more!”

You can even combine the else statement with another if statement to make as many alternative choices as you like:

◆   The switch statements :- 

The switch statement is a very useful programming construct in scenarios where a single variable is to be tested for different values. The same programming scenario can be implemented using nested if statements. However, the switch is a more efficient option for this as it creates a table of values and according to the value received, the execution directly jumps to the code block corresponding to that value.The syntax for using the switch statement is as follows –

switch (expression){ case value1: -

Code block if the expression evaluates to a value equal to value1;


case value2: -

Code block if the expression evaluates to a value equal to value2; break;


Code block if the expression evaluates to a value that is not equal to value1 or value2;       }

Sample code that implements this concept has been given below for your reference. Read More