SlideShare a Scribd company logo
Little Coder Program
by
What you’ve learned?
Doing simple drawings using turtle module
Making DecisionsChapter 5
• We know Computer program lets a computer follow instructions,
but so far the computer doesn't know how to make decisions.
Making Decisions
• We know, among this 4 animals one is not like others
• But computer can’t compare them unless we give instruction for
that
• With the "if" instruction, a computer can compare two things and
make a decision
Making Decisions
• Consider the below example
“We might ask, “Are you older than 20?” and if the answer is yes,
respond with “You are too old!”
These sorts of questions are called conditions, and we combine these
conditions and the responses into if statements.
Making Decisions
Example
>>>age=13
>>>if age > 20:
print(“You are too old”)
print('Why are you here?')
print(“Okey, We may continue”);
Example
>>>age=13
>>>if age > 20:
print(“You are too old”)
print('Why are you here?')
print(“Okey, We may continue”);
These instruction will
execute only if the age is
greater than 20
Example
>>>age=13
>>>if age > 20:
print(“You are too old”)
print('Why are you here?')
print(“Okey, We may continue”);
These empty space is important.
Code that is indented the same
number of spaces from the left
margin is grouped into a block, and
whenever you start a new line with
more spaces than the previous
one, you are starting a new block
that is part of the previous one,
like this
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Block 1
Block 2
Block 3
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Block 1
Block 2
Block 3
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Block 1
Block 2
Block 3
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Line of code
Block 1
Block 2
Block 3
Try this !
• Write down a simple python program to store your marks in 3
subjects, and calculate the average mark. If the average mark is
greater than 90, print “You are an excellent student” and “Keep up
the good work”
Try this !
>>>markInMaths=80
>>>markInScience=90
>>>markInLanguage=90
>>>averageMark=(markInMaths+markInScience+markInLanguage)/3
>>>if averageMark > 90:
print(“You are an excellent Student !!”)
print(‘Keep up the good work')
IF then Else statements
Consider the example
• You know where ever there is an if, there are possibilities of an
else too.
NO Yes
Mark=80
If
mark
>90
Print
“Excellent!!”
Print “Try to
improve”
Consider the example
• You know where ever there is an if, there are possibilities of an
else too.
NO Yes
Mark=80
If
mark
>90
Print
“Excellent!!”
Print “Try to
improve”
We’ve declare a variable
mark with value=80
Consider the example
• You know where ever there is an if, there are possibilities of an
else too.
NO Yes
Mark=80
If
mark
>90
Print
“Excellent!!”
Print “Try to
improve”
Checking whether the
value of mark is greater
than 90 or not
Consider the example
• You know where ever there is an if, there are possibilities of an
else too.
NO Yes
Mark=80
If
mark
>90
Print
“Excellent!!”
Print “Try to
improve”
As mark is less than 90,
it will print “Try to
improve”
Consider the example
• You know where ever there is an if, there are possibilities of an
else too.
NO Yes
Mark=92
If
mark
>90
Print
“Excellent!!”
Print “Try to
improve”
Now We’ve changed the
value of mark into 92
Consider the example
• You know where ever there is an if, there are possibilities of an
else too.
NO Yes
Mark=92
If
mark
>90
Print
“Excellent!!”
Print “Try to
improve”
Again checking whether
the value of mark is
greater than 90 or not
Consider the example
• You know where ever there is an if, there are possibilities of an
else too.
NO Yes
Mark=92
If
mark
>90
Print
“Excellent!!”
Print “Try to
improve”
As its greater than 90, it
will print “Excellent”
Example
>>>markInMaths=80
>>>markInScience=90
>>>markInLanguage=90
>>>averageMark=(markInMaths+markInScience+markInLanguage)/3
>>>if averageMark > 90:
print(“You are an excellent Student !!”)
>>> else
print(“Try to Improve”)
>>> print("Want to hear a dirty joke?")
Want to hear a dirty joke?
>>> age = 12
>>> if age == 12:
print("A pig fell in the mud!")
else:
print("Shh. It's a secret.")
Another Example
if and elif Statements
if and elif
• If and elif is used whenever we want to give a condition with else
NO Yes
Mark=50
If
mark
>90
Print
“Excellent!!”
Print “Try to
improve”
Else If
mark
>60
Yes
Print “Poor”
NO
if and elif
• If and elif is used whenever we want to give a condition with else
NO Yes
Mark=50
If
mark
>90
Print
“Excellent!!”
Print “Try to
improve”
Else If
mark
>60
Yes
Print “Poor”
NO
Checking with else
condition
Example
>>>markInMaths=80
>>>markInScience=90
>>>markInLanguage=90
>>>averageMark=(markInMaths+markInScience+markInLanguage)/3
>>>if averageMark > 90:
print(“You are an excellent Student !!”)
>>> elif averageMArk>60
print(“Try to Improve”)
>>>else
print(“Poor”)
>>> age = 12
>>> if age == 10:
print("What do you call an unhappy cranberry?")
print("A blueberry!")
elif age == 11:
print("What did the green grape say to the blue grape?")
print("Breathe! Breathe!")
elif age == 12:
print("What did 0 say to 8?")
print("Hi guys!")
else:
print("Huh?")
What did 0 say to 8? Hi guys!
Another Example
Combining Conditions
Example
>>> if age == 10 or age == 11 or age == 12 or age == 13:
print('What is 13 + 49 + 84 + 155 + 97? A headache!')
else:
print('Huh?')
>>> if age >= 10 and age <= 13:
print('What is 13 + 49 + 84 + 155 + 97? A headache!')
else:
print('Huh?')
Exercise !
Exercise !
• Create an if statement that checks whether the amount of money contained
in the variable money is between 100 and 500 or between 1,000 and 5,000.
Print a message accordingly
• Create an if statement that prints the string “I can buy too many things” if
the variable money contains a number that’s greater than 500, prints “I
can’t buy toys” if it’s less than 300, and prints “I can buy some chocolates”
if it’s less than 100.
End of Chapter 5

More Related Content

Similar to Baabtra.com little coder chapter - 5 (20)

PPTX
Introduction-to-Conditional-Statements-in-Python.pptx
sonybabu
 
PDF
Conditional-Statement.pdf
ssuser7a7cd61
 
ODP
Introduction to Python - Training for Kids
Aimee Maree
 
PDF
Decision and Control Statements.pdf
SrishtiChakraborty5
 
PPTX
Pythonlearn-03-Conditional.pptx
VigneshChaturvedi1
 
PDF
if statements in Python -A lecture class
binzbinz3
 
PPTX
Mastering python lesson2
Ruth Marvin
 
PPT
PythonCourse_03_Conditionals.ppt Python introduction turorial for beginner.
sakchaisengsui
 
PPTX
Introduction to Python programming
Damian T. Gordon
 
PPTX
2-Conditional Statements, decision making (3).pptx
MAHESWARIS55
 
PPTX
New Microsoft PowerPoint Presentation.pptx
shanthi309015
 
PPTX
Programming with python
sarogarage
 
PPT
Decision Structures and Boolean Logic
Munazza-Mah-Jabeen
 
PPTX
Conditional Statements.pptx
Gautam623648
 
PDF
Python unit 2 M.sc cs
KALAISELVI P
 
PPTX
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
PDF
basic of desicion control statement in python
nitamhaske
 
PPTX
Python Flow Control & use of functions.pptx
pandyahm47
 
PPTX
industry coding practice unit-2 ppt.pptx
LakshmiMarineni
 
PPTX
1.4 decision control statements IN PYTHON.pptx
aditigaurphoto
 
Introduction-to-Conditional-Statements-in-Python.pptx
sonybabu
 
Conditional-Statement.pdf
ssuser7a7cd61
 
Introduction to Python - Training for Kids
Aimee Maree
 
Decision and Control Statements.pdf
SrishtiChakraborty5
 
Pythonlearn-03-Conditional.pptx
VigneshChaturvedi1
 
if statements in Python -A lecture class
binzbinz3
 
Mastering python lesson2
Ruth Marvin
 
PythonCourse_03_Conditionals.ppt Python introduction turorial for beginner.
sakchaisengsui
 
Introduction to Python programming
Damian T. Gordon
 
2-Conditional Statements, decision making (3).pptx
MAHESWARIS55
 
New Microsoft PowerPoint Presentation.pptx
shanthi309015
 
Programming with python
sarogarage
 
Decision Structures and Boolean Logic
Munazza-Mah-Jabeen
 
Conditional Statements.pptx
Gautam623648
 
Python unit 2 M.sc cs
KALAISELVI P
 
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
basic of desicion control statement in python
nitamhaske
 
Python Flow Control & use of functions.pptx
pandyahm47
 
industry coding practice unit-2 ppt.pptx
LakshmiMarineni
 
1.4 decision control statements IN PYTHON.pptx
aditigaurphoto
 

More from baabtra.com - No. 1 supplier of quality freshers (20)

PPTX
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
PDF
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 3 stored procedures
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Ad

Recently uploaded (20)

PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Ad

Baabtra.com little coder chapter - 5

  • 2. What you’ve learned? Doing simple drawings using turtle module
  • 4. • We know Computer program lets a computer follow instructions, but so far the computer doesn't know how to make decisions. Making Decisions
  • 5. • We know, among this 4 animals one is not like others • But computer can’t compare them unless we give instruction for that • With the "if" instruction, a computer can compare two things and make a decision Making Decisions
  • 6. • Consider the below example “We might ask, “Are you older than 20?” and if the answer is yes, respond with “You are too old!” These sorts of questions are called conditions, and we combine these conditions and the responses into if statements. Making Decisions
  • 7. Example >>>age=13 >>>if age > 20: print(“You are too old”) print('Why are you here?') print(“Okey, We may continue”);
  • 8. Example >>>age=13 >>>if age > 20: print(“You are too old”) print('Why are you here?') print(“Okey, We may continue”); These instruction will execute only if the age is greater than 20
  • 9. Example >>>age=13 >>>if age > 20: print(“You are too old”) print('Why are you here?') print(“Okey, We may continue”); These empty space is important. Code that is indented the same number of spaces from the left margin is grouped into a block, and whenever you start a new line with more spaces than the previous one, you are starting a new block that is part of the previous one, like this
  • 10. Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Block 1 Block 2 Block 3
  • 11. Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Block 1 Block 2 Block 3
  • 12. Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Block 1 Block 2 Block 3
  • 13. Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Line of code Block 1 Block 2 Block 3
  • 14. Try this ! • Write down a simple python program to store your marks in 3 subjects, and calculate the average mark. If the average mark is greater than 90, print “You are an excellent student” and “Keep up the good work”
  • 15. Try this ! >>>markInMaths=80 >>>markInScience=90 >>>markInLanguage=90 >>>averageMark=(markInMaths+markInScience+markInLanguage)/3 >>>if averageMark > 90: print(“You are an excellent Student !!”) print(‘Keep up the good work')
  • 16. IF then Else statements
  • 17. Consider the example • You know where ever there is an if, there are possibilities of an else too. NO Yes Mark=80 If mark >90 Print “Excellent!!” Print “Try to improve”
  • 18. Consider the example • You know where ever there is an if, there are possibilities of an else too. NO Yes Mark=80 If mark >90 Print “Excellent!!” Print “Try to improve” We’ve declare a variable mark with value=80
  • 19. Consider the example • You know where ever there is an if, there are possibilities of an else too. NO Yes Mark=80 If mark >90 Print “Excellent!!” Print “Try to improve” Checking whether the value of mark is greater than 90 or not
  • 20. Consider the example • You know where ever there is an if, there are possibilities of an else too. NO Yes Mark=80 If mark >90 Print “Excellent!!” Print “Try to improve” As mark is less than 90, it will print “Try to improve”
  • 21. Consider the example • You know where ever there is an if, there are possibilities of an else too. NO Yes Mark=92 If mark >90 Print “Excellent!!” Print “Try to improve” Now We’ve changed the value of mark into 92
  • 22. Consider the example • You know where ever there is an if, there are possibilities of an else too. NO Yes Mark=92 If mark >90 Print “Excellent!!” Print “Try to improve” Again checking whether the value of mark is greater than 90 or not
  • 23. Consider the example • You know where ever there is an if, there are possibilities of an else too. NO Yes Mark=92 If mark >90 Print “Excellent!!” Print “Try to improve” As its greater than 90, it will print “Excellent”
  • 25. >>> print("Want to hear a dirty joke?") Want to hear a dirty joke? >>> age = 12 >>> if age == 12: print("A pig fell in the mud!") else: print("Shh. It's a secret.") Another Example
  • 26. if and elif Statements
  • 27. if and elif • If and elif is used whenever we want to give a condition with else NO Yes Mark=50 If mark >90 Print “Excellent!!” Print “Try to improve” Else If mark >60 Yes Print “Poor” NO
  • 28. if and elif • If and elif is used whenever we want to give a condition with else NO Yes Mark=50 If mark >90 Print “Excellent!!” Print “Try to improve” Else If mark >60 Yes Print “Poor” NO Checking with else condition
  • 29. Example >>>markInMaths=80 >>>markInScience=90 >>>markInLanguage=90 >>>averageMark=(markInMaths+markInScience+markInLanguage)/3 >>>if averageMark > 90: print(“You are an excellent Student !!”) >>> elif averageMArk>60 print(“Try to Improve”) >>>else print(“Poor”)
  • 30. >>> age = 12 >>> if age == 10: print("What do you call an unhappy cranberry?") print("A blueberry!") elif age == 11: print("What did the green grape say to the blue grape?") print("Breathe! Breathe!") elif age == 12: print("What did 0 say to 8?") print("Hi guys!") else: print("Huh?") What did 0 say to 8? Hi guys! Another Example
  • 32. Example >>> if age == 10 or age == 11 or age == 12 or age == 13: print('What is 13 + 49 + 84 + 155 + 97? A headache!') else: print('Huh?') >>> if age >= 10 and age <= 13: print('What is 13 + 49 + 84 + 155 + 97? A headache!') else: print('Huh?')
  • 34. Exercise ! • Create an if statement that checks whether the amount of money contained in the variable money is between 100 and 500 or between 1,000 and 5,000. Print a message accordingly • Create an if statement that prints the string “I can buy too many things” if the variable money contains a number that’s greater than 500, prints “I can’t buy toys” if it’s less than 300, and prints “I can buy some chocolates” if it’s less than 100.