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

Class003_ Conditionalss

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Class003_ Conditionalss

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Session Code CODR-912-BC-003

Module Basic

Teaching Unit Conditionals

Learning Outcome Boolean variable,Conditionals: if, if else,


elif; Logical Operators

Resources Teacher:
1. Laptop along with audio and video
exchange
2. Notebook and Pen(To note any
development from session)
Student Resources
1. Laptop along with audio and video
exchange
2. Notebook and Pen(To keep note of
important parts in the session)

Duration 50 Mins

Structure Warm-up 2 Mins


Pace-up Activity 5 Mins
Knowledge Transfer 10 Mins
Student Led Activity 20 Mins
Short Quiz 8 Mins
Heads up tip for next class 5 Mins

Copyright © 2020 by Toppr Technologies Pvt. Ltd.


All rights reserved. No part of this document may be distributed, or transmitted in any form or by any means, including photocopying,
recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

1
Step Say Perform

Warm up Hi s​ tudent name​, ​how are you? Try to make the


(2 Mins) Are you excited for the class? student speak.
Do you remember the last class? Engage with the
student in
conversation.

Interaction In the last class, we learnt about Variables and Ask questions,
(5 Mins) Data types. and prompt
● Meaning of variables answers.
● Rules of naming variable
● Data types: int, float, String
● Mathematical operations on int and float

Today we will learn about conditionals. Explain the


meaning of
“I will let you play the video game, only if you condition using a
complete your assignment.” real life example.

Have you heard something like this from your If the student
parents or teachers? suggests any
example go with
Here, the condition is “completing the it and explain
assignment” what is the
condition and the
And if the condition is fulfilled or in other words action to be taken
is “True” if the condition is
true, in their own
Then the action of playing video game is example.
allowed or “executed”

Teacher shares the screen and open Repl.it

Knowledge Similar situations can be represented in Teacher Activity 1:


Transfer programming using the i​ f ​statement. Repl.it

Whatever is written after the keyword, i​ f​ is the


condition​.
We know that the condition here is ​True​, i.e 10
is greater than 9, so the statement under ​if​ will
be executed.

Copyright © 2020 by Toppr Technologies Pvt. Ltd.


All rights reserved. No part of this document may be distributed, or transmitted in any form or by any means, including photocopying,
recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

2
Let’s see what happens if we put a F
​ alse
condition after ​if

Here, as there is no statement for the computer


to run, there is no output.

If we want the computer to do something


specific if the condition is ​False, ​then we have
to use the statement called ​if else.

Here we have two blocks of code.

The block below ​if statement ​is executed


only when the ​condition is True
The block below the ​else statement ​is
executed only when the ​condition is False.

Until now, we saw two conditional statements Teacher Activity 2:


in Python: Syntax
● If statement
● If else statement

Now, the most important thing in these


statements is the ​condition.
Did you notice that a ​condition​ has only two
values, either ​True ​or ​False.
Like we store numbers in variables, we can
also store these ​values of conditions​ in
variables.

These variables have a special name,


Boolean Variable.

So, if we write ​a=8>1, ​then the value of ​a​ is


True, ​as the condition is true.

Copyright © 2020 by Toppr Technologies Pvt. Ltd.


All rights reserved. No part of this document may be distributed, or transmitted in any form or by any means, including photocopying,
recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

3
Similarly, if we write ​b=8<1, ​then the value of
b​ is ​False, ​as the condition is false.

And the ​data type​ of ​a ​and ​b ​is ​Boolean.

The direct way to check the data type of any


variable is using the function, ​type

So, if we write ​type(a) ​or​ type(b) ​the output is


bool, ​which stands for boolean variable.

Now, let’s do some activity to check how much


you have learned.

● Stop sharing screen


● Ask the student to share screen
● Click on Student Activity 1: Conditionals

The goal of this activity is to write a program Student Activity 1:


which takes input from the user and check if it Conditionals
is even or odd.

So, the first step is to get a number from the Explain the
user. ​input ​function helps us in doing so, but question and
one issue with input function is that it takes guide the student
input in ​String​. to fill in the
blanks.
So to get a number in variable n ​ um, ​we need to
convert S
​ tring​ into i​ nt.​ This change of data
type can be done by the function ​int

Copyright © 2020 by Toppr Technologies Pvt. Ltd.


All rights reserved. No part of this document may be distributed, or transmitted in any form or by any means, including photocopying,
recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

4
Now, we have a valid number in variable num.
Can you tell me when a number is even??

For a number to be even, it must be divisible by


2, i.e. when the number is divided by 2, the
remainder is zero.

Do you remember how to find the remainder??

Yes, the Modulus operator is used to find the


remainder.

So, ​num%2 ​will give the remainder.

We want the remainder to be equal to zero.

Do you remember how to compare if two


things are equal?

Yes, using the double equal to operator.

Thus, n
​ um%2==0​ will be true if num is divisible
by 2 and false if num is not divisible by 2.

Great!! You wrote a program to check whether a


number is even or not.

Now, let's learn something more.

● Ask the student to stop sharing the screen


● Share your screen and open teacher activity link 3

So, till now we have learned about two Teacher Activity 3:


conditional statements i​ f​ and ​if else, w
​ e also Grading System
learned about ​boolean variables​ and
relational operators

We also used the ​input f​ unction to take values


from the user and then used the ​int f​ unction to
convert the input into a number.

Now, let’s learn about one more conditional


statement.

Copyright © 2020 by Toppr Technologies Pvt. Ltd.


All rights reserved. No part of this document may be distributed, or transmitted in any form or by any means, including photocopying,
recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

5
Imagine a situation, which can have more than Click on grading
just one condition, like a grading system. system.png to
open the image

For such a type of condition we have a different


conditional statement which is basically an
extension of i​ f else​ statement.

After the else part we add another if else Click on elif.png


condition and so on.
This is called the ​elif statement

So, first we take the percentage from the user


using the input function.
As percentage can be a decimal number, so we
convert the percentage into float using the float
function.

Now, the first condition according to the table is


that if the percentage is between 80 and 100
then the grade will be A.

Here, 80 and 100 both are included, so the


condition must be ​p>=80 AND p<=100

This condition actually is composed of two


conditions: p>=80 and p<=100, so to combine
the two we use the ​logical operator, “and”

Explain the whole


program, step by
step.

Different Logical operators are:


● and
● or

Copyright © 2020 by Toppr Technologies Pvt. Ltd.


All rights reserved. No part of this document may be distributed, or transmitted in any form or by any means, including photocopying,
recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

6
● not

and​ is used when we want both the conditions


to be either true or false

or ​is used when we want either of the two


conditions to be true or false

not​ is used just to convert a true condition into


false and vice versa.

● Stop sharing your screen


● Ask student to share their screen
● Ask student to open activity 2: Relational and logical operators

Let’s revise what Relational and Logical Student Activity 2:


operators are and solve some questions. Relational and
Logical operators
Guide the student
to open images of
Relational and
logical operators
on the left side

Now that we have learnt so many concepts, you


can apply them to build some things.

Activity 3 and 4 are for you to try. Choose either


activity 3 and 4
according to the
time limit.

In Activity 3, you have to create a Calculator. Ask student to


Code to input the two numbers and the choice click on S
​ tudent
of operation is already given with some blanks. Activity 3:
You have to complete the code of elif statement Calculator

In Activity 4, you have to input the grade from Student Activity 4:


the student and display the percentage range Report Card
they scored.

Heads up for the In the next class we will learn about some data
next class structures of python.

BID GOOD BYE & END CLASS

Copyright © 2020 by Toppr Technologies Pvt. Ltd.


All rights reserved. No part of this document may be distributed, or transmitted in any form or by any means, including photocopying,
recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

7
Resources:

Activity Name Links

Teacher Activity 1 Repl link https://repl.it/languages

Teacher Activity 2 Syntax: if and if else https://drive.google.com/file/d/1JY


0MStnz--hI-TYFl5PDvnRF8c7gQHd
d/view?usp=sharing

Teacher Activity 3 elif https://repl.it/@ShailjaGupta/elif#


grading%20system.png

Student Activity 1 Conditionals https://repl.it/@ShailjaGupta/Con


ditionals#main.py

Student Activity 2 Relational and Logical https://repl.it/@ShailjaGupta/Relat


Operators ional-and-Logical-Operators

Student Activity 3 Calculator https://repl.it/@ShailjaGupta/Calc


ulator#main.py

Student Activity 4 Report Card https://repl.it/@ShailjaGupta/Rep


ort-card#main.py

Copyright © 2020 by Toppr Technologies Pvt. Ltd.


All rights reserved. No part of this document may be distributed, or transmitted in any form or by any means, including photocopying,
recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

You might also like