Professional Documents
Culture Documents
3.3 Conditional Statements and Logical Operators
3.3 Conditional Statements and Logical Operators
Интегрированные среды
разработки программ.
Программаларды құрудың
кіріктірілген орталары.
Demo lesson:
Conditional Statements and Logical
operators
Оператор выбора
Таңдау операторы
YOU WILL:
3
Select
таңдау
выбирать
4
to compare
салыстыру -
сравнивать
5
conditional шартты -
условный
6
Indentation
шегініс- отступ
7
value
мән -
значение
8
variable айнымалы -
переменная
9
Discuss the following pictures
10
Conditional statements
People make decisions everyday.
To drink a cup of tea, firstly, we must boil water in a kettle.
Temperature of boiling is 100 Celsius.
Let us understand if water is boiled or not.
We can simply write the following code:
temp = int (input (“What’s temperature of water? ”)
if temp == 100:
print (“It is boiled. Have a nice tea time!”)
In this code we make decisions by using ‘if’ function. So, if temperature of water
becomes equal to 100 degrees Centigrade it will boil and we can have a cup of tea.
11
If / else statement
12
For example, let us ‘program’ the following situation:
As you know, if temperature outside reaches -30 degrees, school will cancel
the lessons. So let us write a code that will check if it is possible to stay home
or not.
Code:
int temp = int(input(“What’s temperature today?”))
if temp <= -30:
print(“Tadaaa, stay home and have sweet dreams!”)
else:
print(“Hey, get up! You have lessons today!”)
13
Switch
Switch case statements are a substitute for long if statements that compare
a variable to several integral values.
● The switch statement is a multiway branch statement. It provides
an easy way to dispatch execution to different parts of code
based on the value of the expression.
● Switch is a control statement that allows a value to change
control of execution.
14
Flow Diagram
15
Syntax:
16
Important Points about Switch Case Statements:
The expression provided in the switch should result in a constant value otherwise it would not
be valid.
Valid expressions for switch:
17