Problem Solving Using Computer
Course Code: BCAC 0018
Lecture – 17&18
Course: BCA I Year I Semester
By: Mr. Sanjiv Agrawal
[email protected] +91-8923015116
Structure of Python Program
•The typical structure of a python program include 3 parts:
i.Import statements // import statements are used to
include library files to the python program
ii.Function definitions //This section include the definitions
of various functions written in a Python Program
iii.Program statements // This section include the set of
statements for solving the given problem.
Elements of Python
• Python has 4 components:
1. IDLE (Python GUI): It is a cross
platform GUI Integrated Development
Environmental that is provided with
Python for editing and running a
Python programs. It is a bundled set of
software’s tools such as Python Shell
for Scripting programs and text editor
for creating and modifying Python’s
source code, a debugger for finding
error, help system etc.
2. Module Docs: This component allows us to access the
python documents such as build in modules, DLLs, libraries,
packages etc.
3. Python (Command line): Python can also be access from
the command line. Command line mode provide very less
features in comparison to IDLE but it is fast.
4. Python Manual: This component include various
documents related to Python such as: installation cum
setup guide, tutorials, Python API , FAQs etc.
Python IDE
Python IDE (Integrated Development Environment)
understands the code significantly better than a text editor.
It is a program exclusively built for software development.
It is designed with a set of tools that all work together:
•Text editor
•Compiler
•Debugging
•Build automation
•Libraries, and many more to speed up the work.
Different Python IDEs
• Python is a programming language with many different
IDEs available.
• Each IDE has its unique features and benefits.
• Some popular IDEs are listed below:
• IDLE
• PyCharm
• Visual Studio Code
• Sublime Text 3
• Atom
• Jupyter
• Spyder
• PyDev
• Thonny
Selection of right Python IDE
• Requirements vary from programmer to
programmer.
• It is one’s own choice to pick the right tool that is
best suited for the task at hand.
• Beginners need to use a simple tool with few
customizations, whereas experts require tools with
advanced features to bring new updates.
• A few suggestions are given next:
1. Depending on Expertise:
•Beginners should start with IDLE and Thonny as they do not
have complex features and are pretty easy to learn.
•Intermediate: PyCharm, VS Code, Atom, and Sublime Text 3
are solid solutions for intermediate users.
•For data science learners, Jupyter Notebooks and Google
Colaboratory are preferred.
2. Depending on Objective:
•Data Science: Spyder, Jupyter Notebook, and PyCharm Pro
(Paid)
•Web Development: Visual Studio Code and PyCharm Pro
(Paid)
•Scripting: Atom, PyDev, Sublime Text 3, and PyCharm (Free)
Python Interpreter
• Python is a high level language.
• Computer understand only machine language or binary
language which is also known as low level language.
• The job is to translate programming code written in high
level language to low level language.
• This can be done with the help of two type of software:
Compiler and Interpreter.
• Python is an interpreted language, which means the source
code of a Python program is converted into byte-code that
is then executed by the Python Virtual Machine.
Python Code Execution
• Source code you type is translated to byte code, which is
then run by the Python Virtual Machine (PVM). Your code
is automatically compiled, but then it is interpreted.
Python interpreter performs the following steps to execute a Python
program or run a set of instruction in interactive mode:
•Step-1: The interpreter read a Python code or instruction. Then it
verifies that the instruction is well formatted, i.e. it checks the syntax of
each line. If it encounters any error, it immediately halts the translation
and shows an error message.
•Step-2: If there is no error, i.e. if the Python instruction or code is well
formatted then the interpreter translates it into its equivalent form in
low language called ‘Byte Code’. Thus, after successful execution of
Python script or code, it is completely translated into byte code.
•Step-3: Byte code is sent to the Python Virtual Machine (PVM). Here
again the byte code is executed on PVM. If an error occurs during this
execution then the execution is halted with an error message.
Python as a Calculator
• Python can be used as a calculator to compute arithmetic
operations like addition, subtraction, multiplication and
division.
• Python can be used as a calculator to make simple
arithmetic calculations.
• Simple arithmetic calculations can be completed at the
Python Prompt.
• The Python REPL shows three arrow
symbols >>> followed by a blinking cursor. Programmers
type commands at the >>> prompt then hit [ENTER] to
see the results.
• >>> 5 + 3
>>> 8
Python Shell
• Python Shell is the command line interpreter that
executes your Python programs, other pieces of Python
code, or simple commands.
• A command line, also known as a command prompt, is a
type of interface.
• Python has two basic modes: script and interactive.
• Interactive mode is a command line shell which gives
immediate feedback for each statement, while running
previously fed statements in active memory.
Indentation
• Indentation in Python refers to the (spaces and tabs) that
are used at the beginning of a statement. The
• statements with the same indentation belong to the same
group.
• For Example
a=2
print(a)
if a==3 :
print(“hello world”)
else :
print(“ bye world”)