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


Performing Actions After a for Loop



Download 2,02 Mb.
Pdf ko'rish
bet49/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   45   46   47   48   49   50   51   52   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Performing Actions After a for Loop
What will happen when a “for loop” finishes execution? Normally, you may want to summarize an
output or continue with other work that your code must complete. Well, in our previous example,
the code is well indented; however, if the code is after the loop, then it will be executed once since
it  wasn’t  indented.  Let  us  include  an  appreciation  message  to  the  magicians  for  their  wonderful
work. This message will be a group message instead of the personalized messages we have written
before. To do that, we have to place our message after the for loop. Additionally, we won’t indent
this line of code. An example will clarify these properly.
magicians_names =[“Greg,” “Perpetual,” “Amos”]
for magician in magicians_names:
print(f “{magician.title()}, you did an excellent trick today!”)
print(f “Keep the good work going every day, (magician.title()}. \n”)
print(“We appreciate your wonderful work. It was a masterpiece performance!”)
The  only  inclusion  of  this  line  of  codes  is  the  last  statement.  If  you  look  closely,  the  first  two
print()  methods  were  properly  indented.  However,  the  third  one  is  different;  hence,  it  will  be
printed once. The output will be as follows.
Greg, you did an excellent trick today!
Keep the good work going every day
Perpetual, you did an excellent trick today!
Keep the good work going every day
Amos, you did an excellent trick today!
Keep the good work going every day
We appreciate your wonderful work. It was a masterpiece performance!

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   45   46   47   48   49   50   51   52   ...   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