SlideShare a Scribd company logo
1 of 12
Download to read offline
Beginnings of programming in Python
Artur Machura
08.05.2023, Katowice
Conditional structures and boolean logic
Abstract
▪ Boolean variables
▪ Relationship operators
▪ Logical operators
▪ „If” and „else” constructs
▪ Nested conditional
structures
▪ Comparing text strings
▪ Practical exercises
Boolean variables
▪ A Boolean variable can take only
one of two values true or false.
Boolean variables are very often
used to set the option whether a
certain condition is met.
▪ Example
If YouHaveTime >= 60 minut
will_see_presentations = true
else:
will_see_presentations = false
In the 19th century,
George Bool
introduced a system
to mathematics that
makes it possible to
perform calculations
based on abstract
concepts such as
true and false.
Relationship operators
Operator in Python definition example in Python
> greater than x > y
Is x greater than y ?
< less than x < y
Is x less than y ?
>= greater than or equal
to
x >= y
Is x greater than or equal to y ?
<= less than or equal to x <= y
Is x less than or equal to y ?
== equal to x == y
Is x equal to y ?
!= unequal x != y
Is x unequal to y ?
Logical operators
(Using logical operators you can create extended Boolean
expressions)
operator definition example in Python
and The expression and returns true only
if both subexpressions are true.
x>y and a<b
Whether x is greater than y
and a is less than b?
or Or expression returns true, only when
one of the sub-expressions returns
true.
x == y or y ==z
Is x equal to y or x equal to z ?
not The not operator negates the value of
an expression.
not (x > y)
Does the expression x > y
return false ?
„If”, „else” construct
If time >= 60 minut
will_see_presentations = true
else:
will_see_presentations = false
Nested conditional structures
(To check more than one condition, conditional
structures can be nested.)
If time >= 60 minut
will_see_presentations = true
If notebook = true
will_take_notes = true
print (’note lesson’)
else:
will_take_notes = false
else:
will_see_presentations = false
Comparing text strings
▪ Python allows you to
compare text strings. This
allows you to create
conditional structures.
▪ ASCII codes are placed in
the computer's memory
(https://www.w3schools.c
om/charsets/ref_html_asci
i.asp )
▪ Python compares the
values of these codes,
therefore you can
compare:
if ’a’ < ’b’
Example in Python
Password = input (’Enter password: ’)
If password == ’prospero’
Print (’Password is correct’)
else:
Print (’Password is incorrect’)
Practical exercises
▪ Write a Python program to find those
numbers which are divisible by 7 and
multiples of 5, between 1500 and 2700
(both included).
Source: https://www.w3resource.com/python-exercises/python-
conditional-exercise-1.php
Source
▪ Gaddis T., Python dla zupełnie początkujących.
Wydanie IV. Helion 2019.
▪ https://www.w3resource.com/python-
exercises/python-conditional-statements-and-
loop-exercises.php
▪ Official source form Python community
▪ https://docs.python.org/3.11/tutorial/index.ht
ml
Thank you for your
attention! Please submit
any comments on the
software-engineers.org
PhD Artur Machura
arturmachura.info
python_p3.pdf

More Related Content

Similar to python_p3.pdf

Java Programmin: Selections
Java Programmin: SelectionsJava Programmin: Selections
Java Programmin: Selections
Karwan Mustafa Kareem
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operators
Jesus Obenita Jr.
 

Similar to python_p3.pdf (10)

dma_ppt.pdf
dma_ppt.pdfdma_ppt.pdf
dma_ppt.pdf
 
Java Programmin: Selections
Java Programmin: SelectionsJava Programmin: Selections
Java Programmin: Selections
 
basic of desicion control statement in python
basic of  desicion control statement in pythonbasic of  desicion control statement in python
basic of desicion control statement in python
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operators
 
c++ Data Types and Selection
c++ Data Types and Selectionc++ Data Types and Selection
c++ Data Types and Selection
 
130706266060138191
130706266060138191130706266060138191
130706266060138191
 
The Art of Identifying Vulnerabilities - CascadiaFest 2015
The Art of Identifying Vulnerabilities  - CascadiaFest 2015The Art of Identifying Vulnerabilities  - CascadiaFest 2015
The Art of Identifying Vulnerabilities - CascadiaFest 2015
 
Ch4
Ch4Ch4
Ch4
 
Pythonintro
PythonintroPythonintro
Pythonintro
 
M C6java5
M C6java5M C6java5
M C6java5
 

More from University of Economics in Katowice

More from University of Economics in Katowice (20)

python_function.pdf
python_function.pdfpython_function.pdf
python_function.pdf
 
python_p4_v2.pdf
python_p4_v2.pdfpython_p4_v2.pdf
python_p4_v2.pdf
 
python_p2v2_publikacja.pdf
python_p2v2_publikacja.pdfpython_p2v2_publikacja.pdf
python_p2v2_publikacja.pdf
 
python_p1.pdf
python_p1.pdfpython_p1.pdf
python_p1.pdf
 
TechnologyStack_basicsv2.pdf
TechnologyStack_basicsv2.pdfTechnologyStack_basicsv2.pdf
TechnologyStack_basicsv2.pdf
 
InitiateAEv2.pdf
InitiateAEv2.pdfInitiateAEv2.pdf
InitiateAEv2.pdf
 
barplotv4.pdf
barplotv4.pdfbarplotv4.pdf
barplotv4.pdf
 
Initiation the Java web application project in the Google App Engine
Initiation the Java web application project in the Google App EngineInitiation the Java web application project in the Google App Engine
Initiation the Java web application project in the Google App Engine
 
ie.pdf
ie.pdfie.pdf
ie.pdf
 
puś.ppt
puś.pptpuś.ppt
puś.ppt
 
swd.pdf
swd.pdfswd.pdf
swd.pdf
 
EARv3.pdf
EARv3.pdfEARv3.pdf
EARv3.pdf
 
Projektowanie i implementacja usług sieciowych
Projektowanie i implementacja usług sieciowychProjektowanie i implementacja usług sieciowych
Projektowanie i implementacja usług sieciowych
 
Angular10302021
Angular10302021Angular10302021
Angular10302021
 
Środowisko PWA
Środowisko PWAŚrodowisko PWA
Środowisko PWA
 
Kolo REST
Kolo RESTKolo REST
Kolo REST
 
Inicjacja wg OpenUP
Inicjacja wg OpenUPInicjacja wg OpenUP
Inicjacja wg OpenUP
 
Dyscyplina zarządzania projektami wg OpenUP
Dyscyplina zarządzania projektami wg OpenUPDyscyplina zarządzania projektami wg OpenUP
Dyscyplina zarządzania projektami wg OpenUP
 
Atrybut zgodności
Atrybut zgodnościAtrybut zgodności
Atrybut zgodności
 
Wstęp do dyscypliny wymagań w projektach IT
Wstęp do dyscypliny wymagań w projektach ITWstęp do dyscypliny wymagań w projektach IT
Wstęp do dyscypliny wymagań w projektach IT
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 

python_p3.pdf

  • 1. Beginnings of programming in Python Artur Machura 08.05.2023, Katowice Conditional structures and boolean logic
  • 2. Abstract ▪ Boolean variables ▪ Relationship operators ▪ Logical operators ▪ „If” and „else” constructs ▪ Nested conditional structures ▪ Comparing text strings ▪ Practical exercises
  • 3. Boolean variables ▪ A Boolean variable can take only one of two values true or false. Boolean variables are very often used to set the option whether a certain condition is met. ▪ Example If YouHaveTime >= 60 minut will_see_presentations = true else: will_see_presentations = false In the 19th century, George Bool introduced a system to mathematics that makes it possible to perform calculations based on abstract concepts such as true and false.
  • 4. Relationship operators Operator in Python definition example in Python > greater than x > y Is x greater than y ? < less than x < y Is x less than y ? >= greater than or equal to x >= y Is x greater than or equal to y ? <= less than or equal to x <= y Is x less than or equal to y ? == equal to x == y Is x equal to y ? != unequal x != y Is x unequal to y ?
  • 5. Logical operators (Using logical operators you can create extended Boolean expressions) operator definition example in Python and The expression and returns true only if both subexpressions are true. x>y and a<b Whether x is greater than y and a is less than b? or Or expression returns true, only when one of the sub-expressions returns true. x == y or y ==z Is x equal to y or x equal to z ? not The not operator negates the value of an expression. not (x > y) Does the expression x > y return false ?
  • 6. „If”, „else” construct If time >= 60 minut will_see_presentations = true else: will_see_presentations = false
  • 7. Nested conditional structures (To check more than one condition, conditional structures can be nested.) If time >= 60 minut will_see_presentations = true If notebook = true will_take_notes = true print (’note lesson’) else: will_take_notes = false else: will_see_presentations = false
  • 8. Comparing text strings ▪ Python allows you to compare text strings. This allows you to create conditional structures. ▪ ASCII codes are placed in the computer's memory (https://www.w3schools.c om/charsets/ref_html_asci i.asp ) ▪ Python compares the values of these codes, therefore you can compare: if ’a’ < ’b’ Example in Python Password = input (’Enter password: ’) If password == ’prospero’ Print (’Password is correct’) else: Print (’Password is incorrect’)
  • 9. Practical exercises ▪ Write a Python program to find those numbers which are divisible by 7 and multiples of 5, between 1500 and 2700 (both included). Source: https://www.w3resource.com/python-exercises/python- conditional-exercise-1.php
  • 10. Source ▪ Gaddis T., Python dla zupełnie początkujących. Wydanie IV. Helion 2019. ▪ https://www.w3resource.com/python- exercises/python-conditional-statements-and- loop-exercises.php ▪ Official source form Python community ▪ https://docs.python.org/3.11/tutorial/index.ht ml
  • 11. Thank you for your attention! Please submit any comments on the software-engineers.org PhD Artur Machura arturmachura.info