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

PPTX
Presentación de obesidad
PDF
Dropdownmenu PHP
PPTX
Java
PPTX
Presentation endurance
PPTX
Medicina Humana_Slideshare_Obesidad
PPTX
Java ppt
PDF
Java Virtual Machine - Internal Architecture
Presentación de obesidad
Dropdownmenu PHP
Java
Presentation endurance
Medicina Humana_Slideshare_Obesidad
Java ppt
Java Virtual Machine - Internal Architecture

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

PPTX
Programming fundamentals lecture 3
PPTX
Python 101: Python for Absolute Beginners (PyTexas 2014)
PPTX
Lecture on Fundamentals of Python Programming-2
PDF
Python! An Introduction
PPTX
3 intro inequalities review
PDF
Quantitative Methods for Lawyers - Class #15 - R Boot Camp - Part 2 - Profess...
PDF
Spss series - data entry and coding
PDF
CPAP.com Introduction to Coding: Part 1
PDF
Code, Comments, Concepts, Comprehension – Conclusion?
PPTX
pseudocode and Flowchart
PPT
Cst test taking strategies (math)
PPTX
Vba Class Level 1
PDF
Conditional-Statement.pdf
PPTX
Whole numbers and integers
PPTX
Chap7_b Control Statement Looping (3).pptx
PPT
Accelerated math directions
PPT
Accelerated Math Directions
PPT
Inequalities ppt revised
PPT
Place Value and Decimals
PDF
powerpoint 1-19.pdf
Programming fundamentals lecture 3
Python 101: Python for Absolute Beginners (PyTexas 2014)
Lecture on Fundamentals of Python Programming-2
Python! An Introduction
3 intro inequalities review
Quantitative Methods for Lawyers - Class #15 - R Boot Camp - Part 2 - Profess...
Spss series - data entry and coding
CPAP.com Introduction to Coding: Part 1
Code, Comments, Concepts, Comprehension – Conclusion?
pseudocode and Flowchart
Cst test taking strategies (math)
Vba Class Level 1
Conditional-Statement.pdf
Whole numbers and integers
Chap7_b Control Statement Looping (3).pptx
Accelerated math directions
Accelerated Math Directions
Inequalities ppt revised
Place Value and Decimals
powerpoint 1-19.pdf
Ad

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

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

Recently uploaded (20)

PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
How to Confidently Manage Project Budgets
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Build Multi-agent using Agent Development Kit
PDF
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
PDF
Become an Agentblazer Champion Challenge Kickoff
PPTX
Presentation of Computer CLASS 2 .pptx
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
ai tools demonstartion for schools and inter college
A REACT POMODORO TIMER WEB APPLICATION.pdf
Softaken Excel to vCard Converter Software.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Upgrade and Innovation Strategies for SAP ERP Customers
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
top salesforce developer skills in 2025.pdf
The Role of Automation and AI in EHS Management for Data Centers.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
How to Confidently Manage Project Budgets
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Build Multi-agent using Agent Development Kit
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Become an Agentblazer Champion Challenge Kickoff
Presentation of Computer CLASS 2 .pptx
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
How to Choose the Right IT Partner for Your Business in Malaysia
How Creative Agencies Leverage Project Management Software.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
ai tools demonstartion for schools and inter college

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.