SlideShare a Scribd company logo
Programming
with
Python
Content to be discuss …
• Variables
• Operands and Expressions
• Conditional Statements
Variables
• Variables are the names given to data that we need to store and
manipulate in our program.
• For example ,to store the age of the user ,we can write a variable
age and it is defined as below.
age = 0 or age = 50
After we define age ,the program will allocate some memory to
store this data.
• Every time we declare a variable ,some initial value must be given
to it.
• We can also define multiple variables at a time.
For ex: age, name=30,’Peter’
This is same as age=30
name=‘Peter’
• The user name can contain any letters (lower case or upper case)
numbers or underscores(-) but the first character shouldn’t be a
number
• For Ex: userName,user_Name,user_Name2 etc.. Are valid.
• But… 2user_name ,2userName ..are not valid
• Variable names are case sensitive .username and userNAME are
not same.
• Normally two conventions are used in Python to denote
variables. Camel case notation or use underscores .
• Camel case is the practice of writing the compound words with
mixed casing. For ex:”thisIsAvariableName”
• Another is to use underscores (-).
Some precautions
• This separates the words.For example:
“user_Name_variable”
• In the above example age=30,the ‘=‘ sign is
known as Assignment Sign
• So the statements x=y and y=x have different
meanings in programming.
Basic Operators
• Python accepts all the basic operators like + (addition),
(subtraction),*(multiplication), / (division), //(floor division),
%(modulus) and **(exponent).
• For example : if x= 7,y=2
addition: x+y=9
subtraction:x-y=5
Multiplication:x*y=14
Division: x/y=3.5
• Floor division: x // y=3(rounds off the answer to the nearest
whole number)
• Modulus: x%y= 1(Gives the remainder when 7 is divided by 2
• Exponent : x**y=49(7 to the power of 2)
Additional assignment Operators
• +=: x+= 2 is same as equal to x=x+2
• Similarly for subtraction x-=2 is
same as x=x-2
Data Types
• Integers are numbers with no decimal parts like 2 , -5 , 27, 0 ,
1375 etc..
• Float refers to a number that has decimal parts. Ex: 1.2467 ;
-0.7865 ; 125.876
• userHeight = 12.53 userWeight = 65.872
• String: String refers to text. Strings are defined within single quotes.
• For Ex: Variable Name = ‘initialvalue’
• VariableName=“initial value”
• userName=‘peter’ ,userSpouseName=“Mary” userAge =“35” here
“35” is a string
• Multiple substrings can be combined by using the concatenate
sign(+)
• Ex:”Peter”+ “Lee” is equivalent to the string “PeterLee”
Type Casting
• Type casting helps to convert from one data type to another .i.e
from integer to a string or vice versa.
• There are three built in functions in Python int(); str() ;
float()
• To change a float to an integer type int(7.3256).
The output is 7
• To change a string into integer int(“4”).The output is 4
• Ex: int(“RAM”) ----- returns syntax error
• int(“3.7654”) -------returns syntax error
• The str() function converts an integer or a float to a string.
• Ex: str(82.1) The output is “82.1”
• Ex: str(757) The output is “757”
• Ex: str(Ram) The output is “Ram”
Conditional Statement
• if statement
• if… else statement
• Nested if statement
Python uses indentation as its
method of grouping statements
Indentation
• Indentation refers to the spaces at the
beginning of a code line.
• Python uses indentation to indicate a block of
code.
Example:
if 7 > 3:
print(“Seven is greater than three *** ")
Python generates an error without indentation
in a block of code.
Assignment Section
Write a python program to :
• find maximum between two numbers
• find minimum between three numbers.
• check whether a number is negative, positive or zero.
• whether a number is divisible by 5 and 11 or not.
• check whether a number is even or odd.
• check whether a year is leap year or not.
• input week number and print week day
• input month number and print number of days in that
month.
• count total number of notes in given amount

More Related Content

What's hot (18)

PPTX
Programming construction tools
sunilchute1
 
PPTX
Loops in Python
Arockia Abins
 
PDF
Unit v
SHIKHA GAUTAM
 
PPTX
Python ppt
Anush verma
 
PDF
Multidimensional arrays in C++
Ilio Catallo
 
PPTX
Iteration
Pooja B S
 
PPTX
Arrays in c
CHANDAN KUMAR
 
PPTX
C++ programming (Array)
طارق بالحارث
 
PDF
C Pointers
omukhtar
 
PDF
Unit iii
SHIKHA GAUTAM
 
PPTX
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
PDF
C intro
SHIKHA GAUTAM
 
PPTX
Python advance
Deepak Chandella
 
PPT
Pointers C programming
Appili Vamsi Krishna
 
PPTX
Pointers in c++
sai tarlekar
 
PDF
Python unit 2 M.sc cs
KALAISELVI P
 
PDF
Arrays-Computer programming
nmahi96
 
Programming construction tools
sunilchute1
 
Loops in Python
Arockia Abins
 
Python ppt
Anush verma
 
Multidimensional arrays in C++
Ilio Catallo
 
Iteration
Pooja B S
 
Arrays in c
CHANDAN KUMAR
 
C++ programming (Array)
طارق بالحارث
 
C Pointers
omukhtar
 
Unit iii
SHIKHA GAUTAM
 
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
C intro
SHIKHA GAUTAM
 
Python advance
Deepak Chandella
 
Pointers C programming
Appili Vamsi Krishna
 
Pointers in c++
sai tarlekar
 
Python unit 2 M.sc cs
KALAISELVI P
 
Arrays-Computer programming
nmahi96
 

Similar to Basics of Python Programming (20)

PPTX
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
PPTX
Review old Pygame made using python programming.pptx
ithepacer
 
PDF
Introduction to Python for Plone developers
Jim Roepcke
 
PPTX
Python Basics by Akanksha Bali
Akanksha Bali
 
PDF
03-Variables, Expressions and Statements (1).pdf
MirHazarKhan1
 
PPTX
Pythonlearn-02-Expressions123AdvanceLevel.pptx
AninditaSarkarNaha
 
PPTX
Review 2Pygame made using python programming
ithepacer
 
PPTX
IoT-Week1-Day1-Lab.pptx
afsheenfaiq2
 
PPTX
Chapter 2: Elementary Programming
Eric Chou
 
PPTX
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
PPT
c-programming
Zulhazmi Harith
 
PPT
PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.
sakchaisengsui
 
PPTX
lecture 2.pptx
Anonymous9etQKwW
 
PPTX
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
PDF
python2oxhvoudhuSGFsughusgdogusuosFU.pdf
rohithzach
 
PPTX
Python basics
Hoang Nguyen
 
PPTX
Python basics
Young Alista
 
PPTX
Python basics
Harry Potter
 
PPTX
Python basics
Fraboni Ec
 
PPTX
Python basics
James Wong
 
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Review old Pygame made using python programming.pptx
ithepacer
 
Introduction to Python for Plone developers
Jim Roepcke
 
Python Basics by Akanksha Bali
Akanksha Bali
 
03-Variables, Expressions and Statements (1).pdf
MirHazarKhan1
 
Pythonlearn-02-Expressions123AdvanceLevel.pptx
AninditaSarkarNaha
 
Review 2Pygame made using python programming
ithepacer
 
IoT-Week1-Day1-Lab.pptx
afsheenfaiq2
 
Chapter 2: Elementary Programming
Eric Chou
 
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
c-programming
Zulhazmi Harith
 
PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.
sakchaisengsui
 
lecture 2.pptx
Anonymous9etQKwW
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
python2oxhvoudhuSGFsughusgdogusuosFU.pdf
rohithzach
 
Python basics
Hoang Nguyen
 
Python basics
Young Alista
 
Python basics
Harry Potter
 
Python basics
Fraboni Ec
 
Python basics
James Wong
 
Ad

Recently uploaded (20)

PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Ad

Basics of Python Programming

  • 2. Content to be discuss … • Variables • Operands and Expressions • Conditional Statements
  • 3. Variables • Variables are the names given to data that we need to store and manipulate in our program. • For example ,to store the age of the user ,we can write a variable age and it is defined as below. age = 0 or age = 50 After we define age ,the program will allocate some memory to store this data. • Every time we declare a variable ,some initial value must be given to it. • We can also define multiple variables at a time. For ex: age, name=30,’Peter’ This is same as age=30 name=‘Peter’
  • 4. • The user name can contain any letters (lower case or upper case) numbers or underscores(-) but the first character shouldn’t be a number • For Ex: userName,user_Name,user_Name2 etc.. Are valid. • But… 2user_name ,2userName ..are not valid • Variable names are case sensitive .username and userNAME are not same. • Normally two conventions are used in Python to denote variables. Camel case notation or use underscores . • Camel case is the practice of writing the compound words with mixed casing. For ex:”thisIsAvariableName” • Another is to use underscores (-). Some precautions
  • 5. • This separates the words.For example: “user_Name_variable” • In the above example age=30,the ‘=‘ sign is known as Assignment Sign • So the statements x=y and y=x have different meanings in programming.
  • 6. Basic Operators • Python accepts all the basic operators like + (addition), (subtraction),*(multiplication), / (division), //(floor division), %(modulus) and **(exponent). • For example : if x= 7,y=2 addition: x+y=9 subtraction:x-y=5 Multiplication:x*y=14 Division: x/y=3.5 • Floor division: x // y=3(rounds off the answer to the nearest whole number) • Modulus: x%y= 1(Gives the remainder when 7 is divided by 2 • Exponent : x**y=49(7 to the power of 2)
  • 7. Additional assignment Operators • +=: x+= 2 is same as equal to x=x+2 • Similarly for subtraction x-=2 is same as x=x-2
  • 8. Data Types • Integers are numbers with no decimal parts like 2 , -5 , 27, 0 , 1375 etc.. • Float refers to a number that has decimal parts. Ex: 1.2467 ; -0.7865 ; 125.876 • userHeight = 12.53 userWeight = 65.872 • String: String refers to text. Strings are defined within single quotes. • For Ex: Variable Name = ‘initialvalue’ • VariableName=“initial value” • userName=‘peter’ ,userSpouseName=“Mary” userAge =“35” here “35” is a string • Multiple substrings can be combined by using the concatenate sign(+) • Ex:”Peter”+ “Lee” is equivalent to the string “PeterLee”
  • 9. Type Casting • Type casting helps to convert from one data type to another .i.e from integer to a string or vice versa. • There are three built in functions in Python int(); str() ; float() • To change a float to an integer type int(7.3256). The output is 7 • To change a string into integer int(“4”).The output is 4 • Ex: int(“RAM”) ----- returns syntax error • int(“3.7654”) -------returns syntax error • The str() function converts an integer or a float to a string. • Ex: str(82.1) The output is “82.1” • Ex: str(757) The output is “757” • Ex: str(Ram) The output is “Ram”
  • 10. Conditional Statement • if statement • if… else statement • Nested if statement Python uses indentation as its method of grouping statements
  • 11. Indentation • Indentation refers to the spaces at the beginning of a code line. • Python uses indentation to indicate a block of code. Example: if 7 > 3: print(“Seven is greater than three *** ") Python generates an error without indentation in a block of code.
  • 12. Assignment Section Write a python program to : • find maximum between two numbers • find minimum between three numbers. • check whether a number is negative, positive or zero. • whether a number is divisible by 5 and 11 or not. • check whether a number is even or odd. • check whether a year is leap year or not. • input week number and print week day • input month number and print number of days in that month. • count total number of notes in given amount