Learning Python: The Ultimate Guide for Beginners to Coding with Python with Useful Tools



Download 2,02 Mb.
Pdf ko'rish
bet81/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   77   78   79   80   81   82   83   84   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Creating Multiple Conditions
When  writing  code,  there  are  situations  that  may  warrant  you  to  verify
multiple conditions simultaneously. For instance, you require conditions to
be false in order to take action. At times, you may want only one condition
to be satisfied. In this situation, you can use the keyword “or” and “and.”
Let  first  use  the  “and”  keyword  to  check  multiple  conditions  in  Python
programming.
Using “AND”
If you want to verify that two expressions are both true at the same time, the
keyword “and” serves that purpose. The expression is evaluated to be true
when both conditions test to return true. However, if one of the condition
falls, then the expression returns false. For instance, you want to ascertain if
two students in a class have over 45 score marks.
>>> score_1 = 46
>>> score_2 = 30
>>> score_1 >=45 and score_2 >= 45
False
>>> score_2 = 47
>>> score_1 >= 45 and score_2 >= 45
True
The program looks complicated but lets me explain it step-by-step. In the
first two lines, we define two scores, score_1, and score_2. However, in line
3, we perform a check to ascertain if both scores are equal to or above 45.
The condition on the right-hand side is false, but that of the left-hand side is
true.  Then  in  the  line  after  the  false  statement,  I  changed  the  value  of
score_2 from 30 to 47. In this instant, the value of score_2 is now greater
than 46; therefore, both conditions will evaluate to true.
In order to make the code more readable, we can use parentheses in each
test. However, it is not compulsory to do such but makes it simpler. Let us


use  parentheses  to  demonstrate  the  difference  between  the  previous  code
and the one below.
(score_1 >= 45) and (score_2 >=45)

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   77   78   79   80   81   82   83   84   ...   126




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish