Algorithms For Dummies



Download 7,18 Mb.
Pdf ko'rish
bet173/651
Sana15.07.2021
Hajmi7,18 Mb.
#120357
1   ...   169   170   171   172   173   174   175   176   ...   651
Bog'liq
Algorithms

 Getting Started

Notice that the condition uses the relational equality operator

==

, and not the 



assignment operator, 

=

. A common mistake that developers make is to use the 



assignment operator rather than the equality operator. Using the assignment 

operator in place of the equality operator will cause your code to malfunction.

The condition always ends with a colon (:). If you don’t provide a colon, Python 

doesn’t know that the condition has ended and will continue to look for additional 

conditions on which to base its decision. After the colon comes any tasks you want 

Python to perform.

You may need to perform multiple tasks using a single if statement. The 

elif


 

clause makes it possible to add an additional condition and associated tasks. A 



clause is an addendum to a previous condition, which is an 

if

 statement in this 



case. The 

elif


 clause always provides a condition, just as the 

if

 statement does, 



and it has its own associated set of tasks to perform.

Sometimes you need to do something no matter what the condition might be. In 

this case, you add the 

else


 clause. The 

else


 clause tells Python to do something 

in particular when the conditions of the 

if

 statement aren’t met.



Notice how indenting is becoming more important as the functions become more 

complex. The function contains an 

if

 statement. The 



if

 statement contains just 

one 

print()


 statement. The 

else


 clause contains two 

print()


 statements.

To see this function in action, type TestValue(1) and press Enter. You see the out-

put from the 

else


 clause. Type TestValue(5) and press Enter. The output now 

reflects the 

if

 statement output. Type TestValue(6) and press Enter. The output 



now shows the results of the 

elif


 clause. The result is that this function is more 

flexible than previous functions in the chapter because it can make decisions.




Download 7,18 Mb.

Do'stlaringiz bilan baham:
1   ...   169   170   171   172   173   174   175   176   ...   651




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
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