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



Download 2,02 Mb.
Pdf ko'rish
bet86/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   82   83   84   85   86   87   88   89   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

if-else Statements
At times, you may want to take certain actions if a particular condition isn’t
met.  For  example,  you  may  decide  what  will  happen  if  a  person  isn’t
qualified  to  play  a  match.  Python  provides  the  if-else  statements  to  make
this possible. The syntax is as follows:


if conditional test
perform statement_1
else
perform statement_2
Let  us  use  our  football  match  qualification  to  illustrate  how  to  use  the  if-
else statement.
person  =18
if person >= 20:
print(“You are qualified for the football match against Valencia.”)
print(“The match is between Arsenal and Valencia.”)
Print(“The Venue is at the Emirate Stadium in England.”)
else:
print(“Unfortunately, you are not qualified to participate in the match.”)
print(“Sorry, you have to wait until you are qualified.”)
The conditional test (if person>=20) is first evaluated to ascertain that the
person is above 20 before it passes to the first indented line of code. If it is
true,  then  it  prints  the  statements  beneath  the  condition.  However,  in  our
example, the conditional test will evaluate to false then passes control to the
else section. Finally, it prints the statement below it since it fulfills that part
of the condition.
Unfortunately, you are not qualified to participate in the match.
(“Sorry, you have to wait until you are qualified.
This program works because of the two possible scenarios to evaluate – a
person  must  be  qualified  to  play  or  not  play.  In  this  situation,  the  if-else
statement works perfectly when you want Python to execute one action in
two possible situations.


Let us try another.
station_numbers = 10
if station_numbers >=12:
print(“We need additional 3 stations in this company.”)
else:
print(“We  need  additional  5  stations  to  meet  the  demands  of  our
audience.”)
The output will be:
We need an additional 5 stations to meet the demands of our audience.

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   82   83   84   85   86   87   88   89   ...   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