0% found this document useful (0 votes)
7 views

Unit1-Intro To Python

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Unit1-Intro To Python

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Unit-1

Introduction to Python Programming

 Programming is an art.
 Programming skill improves my critical thinking.
 Hence I love programming.

A program is a sequence of instructions to computer


for solving our problem.
Introduction to Python Programming
 Python is a high-level programming language which was
created in the late 1980's by Guido van Rossum.

 It was named as a homage to the world famous British


comedy group Monty Python.

 Python places huge emphasis on simplicity and code


readability, making it easy to create applications quickly.

 This easiness and speed makes Python a brilliant language for


us to start off with.

 High-level programming languages allow us to write computer


programs in a language closer to human languages than
computer code.

 Other high-level programming languages include HTML,


scratch, C, BASIC, Pascal and Java.
Introduction to Python Programming

Why Should I Learn Python?


 Python is a brilliant computer language to start off with
because it is both easy to pick up and incredibly
powerful.

 It will be easier for us to learn and quicker for us to


develop programs with Python than other programming
languages.

 It is also easier for us to find out where the mistakes


are.

 It has a simple but effective approach to object-oriented


programming.
Introduction to Python Programming
Why Should I Learn Python?
Continued
 Python is also incredibly versatile.
 We can use it for anything from desktop applications to
games and we can also develop applications for
mobiles too.
 We can find a lot of libraries which will allow us to
extend the functionality of the language itself.
 Finally, Python is cross-platform – which means that
we can write our code for one and it will work the same
on all of the other platforms [Windows, Linux and Mac] .
 This makes things much easier for us to port our
program to each of the Windows, Linux and Mac
platforms.
Introduction to Python Programming
Setting Up
Python:
Python interpreter can be downloaded from the following
website: https://www.python.org/downloads/

The Python Tutorial is found at


https://docs.python.org/3.10/tutorial/index.html#tutorial-
index
Introduction to Python Programming
Setting Up
Python: https://www.python.org/downloads/
Introduction to Python Programming

Installation guide:

1. https://datatofish.com/install-python/

2. https://www.youtube.com/watch?
v=jgDMiCVVC9s
Introduction to Python Programming
Using the Python Shell:
 Python Shell, which runs Python in interactive mode
allows us input a command that can be executed
instantly.
For example,
>>> 2 + 5
Will return 7 as result.
>>> 1 < 5
will return the answer True.
>> >print ('Hello World')
This command will tell the shell to display the words
“Hello World” which it will instantly do.
Introduction to Python Programming
Python
script:
 The Python Shell is perfect for testing out new
commands and seeing how Python works, but it will
not save any of our coding.
 The Integrated Development Learning Environment
(IDLE) is used to edit, translate and execute python
programs.
 To develop a program we need to write our code
and save it in a .py file, which is called a Python
script.
 To do this we just need to click on File > New File at
the top menu which will bring up the editor we are
going to use to develop our programs.
Introduction to Python Programming
Adding comments to our Code:
 In Python we can comment out a line by typing a # at the beginning
of the line.
 Comments are ignored by the interpreter and hence will not be
executed by the computer.
 The comments tell us what the following piece of code is going to
do, which makes it easier when we need to edit things or we need
to find a bug.

Example:
#My first Python Program
Introduction to Python Programming
Writing my first Python Program:
Introduction to Python Programming
Executing my first Python Program:
Step 1: Open the editor by clicking on File > New File
Step 2: Enter the program.
Step 3: Save the program with .py extension by clicking on File > Save As.
Step 4: Run the program by pressing F5 or clicking Run > Run Module.
 The output is displayed on the Python Shell.
Introduction to Python Programming

Online Python interpreter:

https://www.programiz.com/python-programming/online-
compiler/
Python Variables
Python Variables
 Variables are containers for storing data values.
 A variable is created the moment you first assign a value to it.
 A variable can have a short name (like x and y) or a more
descriptive name (age, carName, total_volume).
 x=10
 age=20
 Name=“Jakir”
Rules for Python variables:

A variable name must start with a letter or


the underscore character
A variable name cannot start with a
number
A variable name can only contain alpha-
numeric characters and underscores (A-z,
0-9, and _ )
 Variablenames are case-sensitive (age,
Age and AGE are three different variables)
 Variablecan not be a python reserved
word or keyword.
Python Reserved Words
Printing the value of a variable
print functions is used to print the value of a variable
 print(variable)
 print(“message”, variable)

length= 10
width=5
area= length*width
print (area)
Write a python script to print the area of a
rectangle whose length is 10cm and width is 5cm

length= 10 length= 10
width=5
width=5
area= length*width
area= length*width print ("Area of rectangle=", area, "sqr
cm")
print (“Area of rectangle=”, area, “sqr
print ("Bye”)
cm”)
Print(“Bye”)
OUTPUT
Practice the following examples:
length= 10
width=5
height =10
 Write a python script to print the vol= length*width*height
volume of a room whose length is print ("Volume=", vol, "sqr root")
print ("Bye")
15m, width is 5m and height is 10 m
pi= 3.14
 Write a python script to print radius=10
area= pi*radius*radius
the area of a circle whose print (“Area=", area, "sqr root")
radius is 10cm print ("Bye")

 Write a python script to print base= 10


height=15
the area of a triangle whose area_triangle= 0.5*base*height
base is 10cm and height is print (“Area Triangle=", area_triangle, "sqr
root")
15cm print ("Bye")

You might also like