Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet70/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   66   67   68   69   70   71   72   73   ...   453
LISTINg 3-3: 
 Making an either/or decision
# Define an input variable.
Answer = raw_input(‘Say hello (Y/N)?’)
# Check the value of Answer.
if Answer.upper() == ‘Y’:
# Perform some tasks based on a positive response.
print ‘You typed:’, Answer
print ‘So Hello!’
continues
548592c03.indd 49
2/24/10 12:47:29 PM
www.finebook.ir


50

CHAPTER 3
ImplementIng Structured language elementS
# The user must have typed something else.
else:
# Perform some tasks based on a different response.
print ‘Sorry, you typed:’, Answer, ‘and not Y.’
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
The big thing to notice in this example is that you outdent the 
else
clause and follow it with a 
colon. Every indented statement after the 
else
clause is part of the 
else
portion of the structure. 
The output from this example is similar to the output shown in Figure 3-2. The application asks 
a question and then outputs something based on the response the user provides.
Creating a Decision Tree Using if . . . elif . . . else
Many programming languages provide a special structure to handle complex decisions. IronPython 
keeps things simple by relying on a special form of the 
if
statement, the 
if...elif...else
state-
ment. As you might expect, each 
elif
clause includes a Boolean expression. In many respects, the 
elif
clauses act as the case clauses for the 
Select...Case
structure. Of course, you gain some flexibility 
because the 
elif
clause need not match a particular variable. The 
else
clause acts like the default 
clause for the 
Select...Case
structure. Listing 3-4 shows how to work with the 
elif
clause.

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   66   67   68   69   70   71   72   73   ...   453




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