IT_3.1_RM(PY)
IT_3.1_RM(PY)
Python Programming
What is an Algorithm and Flow Chart
• Algorithm is a sequence of activities to be processed for getting desired
output from given input
• A step by step method for solving a particular problem or doing a task
• Flowchart is a type of diagram that represents an algorithm, workflow or
process, showing the steps as boxes of various kinds, and their order by
connecting them with arrows
• We can see a flow chart as a blueprint of a design you have made for solving
a problem.
What is Programming Language
• Programming Language is also like an English,Telugu…etc.
• A vocabulary and set of grammatical rules for instructing a computer to
perform specific tasks.
• Each language has a unique set of keywords and a special syntax for
organizing program instructions.
• Programming languages are classified as:
Low level language and High level language
It takes less amount of time to analyze the source It takes large amount of time to analyze the source code
code but the overall execution time is slower. but the overall execution time is comparatively faster.
Object-oriented
o Everything in Python is an object. Object oriented programming (OOP) helps you solve a complex problem
intuitively.
o With OOP, you are able to divide these complex problems into smaller sets by creating objects.
Why Python is very easy to read Language ?
• One big change with Python is the use of whitespace to define code: spaces or tabs
are used to organize code by the amount of spaces or tabs.
• This means at the end of each line, a semicolon is not needed and curly braces ({})
are not used to group code.
• Which are both common in C. The combined effect makes Python a very easy to read
language.
4 Reason to Choose Python as First Language
Simple Elegant (Graceful) Syntax
• It's easier to understand and write Python code.
• Why ?Syntax feels Naturals With Example Code
A=12
B=23
sum=A+B
Print(sum)
• Even if you have never programmed before, you can easily guess that this program adds
two numbers and prints it.
Not overly strict
• You don't need to define the type of a variable in Python. Also, it's not necessary to add
semicolon at the end of the statement.
• Python enforces you to follow good practices (like proper indentation). These small things can
make learning much easier for beginners.
Expressiveness of the language
• Python allows you to write programs having greater functionality with fewer(less) lines of code.
• we can build game(Tic-tac-toe) with Graphical interface in less than 500 lines of code
• This is just an example. You will be amazed how much you can do with Python once you learn
the basics
Great Community and Support
• Python has a large supporting community.
• There are numerous active forums online which can be handy if you are stuck
Run Python on Your Operating System
• Install and Run Python in Linux (Ubuntu)
1. Install the following dependencies:
o $ sudo apt-get install build-essential checkinstall
o $sudo apt-get install libsqlite3-dev
o $ sudo apt-get install libbz2-dev
(libreadline-gplv2-dev libncursesw5-dev libssl-dev tk-dev libgdbm-dev libc6-dev)
Video Link : - https://www.youtube.com/watch?v=sKiDjO_0dCQ
2. Go to Download Python page on the official site and click Download Python 3.7.0
3. In the terminal, go to the directory where the file is downloaded and run the command:
o $ tar -xvf Python-3.7.0.tgz
o This will extract your zipped file.
o Note: The filename will be different if you've downloaded a different version. Use the
appropriate filename
4. Go to the extracted directory.
o $ cd Python-3.7.0
5. Issue the following commands to compile Python source code on your Operating
system
o $ ./configure
o $ sudo make altinstall
6. Go to Terminal and type the following to run sample ‘ hello world ‘ Program
ubuntu@RGUKT~$ python3.7.0
>>>print(‘Hellow World’)
Hello World
>>>
4. To set default version as new python series
• Open your .bashrc file by typing in terminal
• ubuntu@RGUKT~$ nano ~/.bashrc.
Then type alias python=python3 on to a new line at the top of the file then save the file with
ctrl+o and close the file with ctrl+x.
Then, back at your command line type
ubuntu@RGUKT~$ source ~/.bashrc.
Now your alias should be permanent.
• Quitting Python
Script from the Command-line
• $python3.7 fileName.py
First Program in Python: Printing a Line of
• Interactive mode
Text
First Program in Python: Printing a Line of
• Script Mode
Text
• Saving as a file
• Type code into a .py file and save it
• To run it type python fileName.py
# hello.py
Comments
# Printing a line of text in Python
print("Welcome to Python!")
Printing Line