Thursday, March 26, 2015

To write  python programs.

root@sagar:/home/sagar/Learn_python#  vim Test.py
Enter your whole code in vim  and exit.

To run python code :
root@sagar:/home/sagar/Learn_python# python Test.py

Lecture 1: Control flow, loops and functions

Booleans:

Before we start with control flow, let's introduce a new variable type called the boolean. This is used to signify  if something is true or false .

Programs 1: 

Happy = True
Sad= False
print 'Am I happy? %s. Am I sad? %s.' % (Happy,Sad)

output : 

Am I hungry? True. Am I thirsty? False.


The if/else statement:

The if/else statement is used to make decisions based on the value of a variable. The general format of the if/else statement is as follows:

Programs 2: 

days_in_feb = 29 # number of days in february
if days_in_feb != 29:
        print 'We are not in a leap year'
else:
        print 'We are in a leap year.'

Output 2:

We are in a leap year.